Showing posts with label object. Show all posts
Showing posts with label object. Show all posts

Sunday, March 11, 2012

Cacluated Field

I am designing an object model and DB and I can't decide where to put
calculated fields... Should it be in the database or the middle-tier?

In other words, if I have an OrderItem on an Order and there are two
columns called "Quantity" and "Cost" I also will want "TotalCost" =
"Quantity x "Cost"... Do I have the "GET" stored proc return this
caculcated value or just create the property in my middle-tier and have
it calculate it there?

Opinions anyone?<josh@.nautilusnet.com> wrote in message
news:1111427709.765197.314850@.f14g2000cwb.googlegr oups.com...
>I am designing an object model and DB and I can't decide where to put
> calculated fields... Should it be in the database or the middle-tier?
> In other words, if I have an OrderItem on an Order and there are two
> columns called "Quantity" and "Cost" I also will want "TotalCost" =
> "Quantity x "Cost"... Do I have the "GET" stored proc return this
> caculcated value or just create the property in my middle-tier and have
> it calculate it there?
> Opinions anyone?

For such a simple calculation, I would do it in either the stored procedure
or perhaps a view - the view is useful if you want to have the value
available to other clients which may not always call your proc, and for ad
hoc queries. You could use a computed column as well, but I haven't used
them much, so I don't really know how they perform with large data sets.

More complex calculations may be better in the middle tier, especially if
you only calculate for relatively small data sets, and if you need to use
mathematical functions which aren't available in TSQL, then you may have no
choice. As in many cases, the best way to get a good answer is to test it
yourself with your own data and see which solution works out better for you.

Simon|||josh@.nautilusnet.com wrote:

> I am designing an object model and DB and I can't decide where to put
> calculated fields... Should it be in the database or the middle-tier?
> In other words, if I have an OrderItem on an Order and there are two
> columns called "Quantity" and "Cost" I also will want "TotalCost" =
> "Quantity x "Cost"... Do I have the "GET" stored proc return this
> caculcated value or just create the property in my middle-tier and have
> it calculate it there?
> Opinions anyone?

First off, I would highly suggest that you have all of these calculated
fields defined in some sort of data dictionary so that you can use a code
generator of some sort to generate it. This lets you change your mind
about implementation details after the fact.

Calculated fields can come down to these types:

1) EXTEND, most common, extended = price * qty
2) FETCH, pull price from items table into orders, trigger action is change
of value of order_detail.item_code.
3) AGGREGATE, any sum, avg, min, max or count() from detail to header
4) DISTRIBUTE, like a fetch, in that a value goes from header to detail,
but triggering action is a change in value in header, and it is pushed to
*all* rows in child table that match on pk/fk. Included for completeness
but considered evil.

All approaches boil down to either materializing in the tables, or not doing
it.

The simplest approach if you don't put them into tables is to create views.
I've done this with a view generator and it is pretty nifty. The danger is
that the very simplicity of the views will obscure very deeply nested
subqueries, which may not be discovered until the system comes under heavy
load.

The other option is to materialize them into the tables. This is considered
evil by relational theorists, but the only real requirement if you do this
is that you not let a casual user update the automated columns. So a
straight command "UPDATE ... SET TotalCost=5 " should fail with an error.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@.(Sec)ure(Dat)a(.com)|||I am just now getting back to this thread. In my opinion the problem
with putting calculations into the the sproc is that it's not possible
to no the calculation until call the sproc again. This feels unnatural
when working with an object model, for example:

OrderItem item = new OrderItem();
item.Quantity = 5;
item.Cost = 10.00;

Response.write(item.Total);

For the above code to work using the "calculations in sproc" method I
would have to hit the database again for item.Total to have a value...|||If you want to see the calculated total immediately, then a view is
probably better than a procedure:

create view dbo.OrdersWithTotalCost
as
select
OrderID,
OrderItemID,
...
/* Other columns from Orders */
...
Quantity,
Cost,
Quantity * Cost as 'Total'
from
dbo.Orders

I'm not sure I understand your concern about hitting the database again
- since your calculation is so simple, you will know the value of Total
before you even INSERT the new order item, and you may not need to
retrieve it again (unless there's further processing in the database,
of course).

If you really want to avoid another query, then one option is to create
an InsertOrderItem stored procedure, which INSERTs the new item and
then returns the total as an output parameter.

Simon|||Simon Hayes wrote:

> If you want to see the calculated total immediately, then a view is
> probably better than a procedure:
> create view dbo.OrdersWithTotalCost
> as
> select
> OrderID,
> OrderItemID,
> ...
> /* Other columns from Orders */
> ...
> Quantity,
> Cost,
> Quantity * Cost as 'Total'
> from
> dbo.Orders
> I'm not sure I understand your concern about hitting the database again
> - since your calculation is so simple, you will know the value of Total
> before you even INSERT the new order item, and you may not need to
> retrieve it again (unless there's further processing in the database,
> of course).
> If you really want to avoid another query, then one option is to create
> an InsertOrderItem stored procedure, which INSERTs the new item and
> then returns the total as an output parameter.

My original suggestion held that the definitions should be stored in a data
dictionary and any implemention, views or sprocs, should be generated from
that.

If you do that, the client (some OO code) can read the dictionary, or you
can generate code for classes, and they can do their own calculations on
the fly for user convenience. You then can independently decide how to
implement the same formulas on the server.

If the implementation is based on a dd, you can try different methods and
change your mind rather painlessly.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@.(Sec)ure(Dat)a(.com)

Friday, February 24, 2012

C# Replication Between Microsoft SQL server 2000 and Microsoft Access

Hi all,
Currently I need to perform in C# merge publication between SQL Server
2000 and Microsoft Access 2000. I tried using Jet Object Replication
COM to perform this but encounter the following error.
Any advice or alternative solution is greatly appreciated.
Thanks.
Rgds,
Winston
Codes
JRO.ReplicaClass rep1 = new JRO.ReplicaClass();
rep1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\\Test\\SyncTest\\SyncTest\\synctest.mdb" ;
rep1.Synchronize("TestSrv.TestDB.TestPub",
JRO.SyncTypeEnum.jrSyncTypeImpExp,
JRO.SyncModeEnum.jrSyncModeDirect);
Errors
System.Runtime.InteropServices.COMException (0x800A0BB9): Arguments
are of the wrong type, are out of acceptable range, or are in conflict
with one another.
at JRO.ReplicaClass.set_ActiveConnection(Object ppconn)
The above error occurs at line:
rep1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\\Test\\SyncTest\\SyncTest\\synctest.mdb" ;
can you post your entire code?
"Winston" <skuzski@.hotmail.com> wrote in message
news:62956cb.0403311901.75d424a1@.posting.google.co m...
> Hi all,
> Currently I need to perform in C# merge publication between SQL Server
> 2000 and Microsoft Access 2000. I tried using Jet Object Replication
> COM to perform this but encounter the following error.
> Any advice or alternative solution is greatly appreciated.
> Thanks.
> Rgds,
> Winston
> Codes
> --
> JRO.ReplicaClass rep1 = new JRO.ReplicaClass();
> rep1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data
> Source=C:\\Test\\SyncTest\\SyncTest\\synctest.mdb" ;
> rep1.Synchronize("TestSrv.TestDB.TestPub",
> JRO.SyncTypeEnum.jrSyncTypeImpExp,
> JRO.SyncModeEnum.jrSyncModeDirect);
> Errors
> --
> System.Runtime.InteropServices.COMException (0x800A0BB9): Arguments
> are of the wrong type, are out of acceptable range, or are in conflict
> with one another.
> at JRO.ReplicaClass.set_ActiveConnection(Object ppconn)
> The above error occurs at line:
> rep1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data
> Source=C:\\Test\\SyncTest\\SyncTest\\synctest.mdb" ;
|||"Hilary Cotter" <hilaryk@.att.net> wrote in message news:<e79fC15FEHA.2732@.tk2msftngp13.phx.gbl>...
> can you post your entire code?
Hi,
The entire code is:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace SyncTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
// InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(176, 120);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(232, 40);
this.button1.TabIndex = 0;
this.button1.Text = "Sync";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(608, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
JRO.ReplicaClass rep1 = new JRO.ReplicaClass();
rep1.ActiveConnection
= "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\\CupaDMS\\SyncTest\\SyncTest\\synctest.m db";
rep1.Synchronize("buildfoliousa\buildfoliousa.insp ections.inspections",
JRO.SyncTypeEnum.jrSyncTypeImpExp, JRO.SyncModeEnum.jrSyncModeDirect);
}
}
}

Tuesday, February 14, 2012

business vs. logic

You have seen a chair in a public room and go back after a while to acquire it. Is it unexpected that the object is not there anymore?

I implement the business logic in stored procedures. Once user orders some service, the actions carry out are: a)check they have sufficient funds on their balance; and, b) a price check is made selecting the latest from pricelist. The newly created job entry refers the price in the pricelist table according to service_id and the issued pricelist date.

These are data validity checks, which must be done in a multiuser database. In the session beginning, user gets prices and funds. These data are not locked throughout the session -- another process may change the records. Therefore, the extra "business" checks are needed to preserve data correctness at the start of every transaction. One way to report the errors would be to raise an error.

Consider the primary-foreign key violations. They are raised by system with severity level of 16. Uniqueness violation is raised with severity 14. The MSSQL reference http://msdn2.microsoft.com/en-us/library/ms164086.aspx tells us that this is a sort of error, which can be corrected by user. Indeed, (s)he can. But the exceptions are unexpected situations. Exception processing consumes huge CPU processing power if some occurs. Normally, programs allocate resources and use them. If resource cannot be allocated -- app exits with exception. It just has nothing to do. However, there is nothing exceptional in shared data access by multiple concurrent processes in a multithread/multiuser/distributed application. Since, we cannot lock the user resources during user session, we should be prepared to concurrent data changes. Therefore, I find the exception raising inappropriate tool.

Consider a situation, when one user is assigned to a group. Nothing prevents from another admin to remove the group at the same time. Therefore, our user management application should be ready to expected "group does not exist" "error" result. I even disagree that this is an error, since it is perfectly valid to have such a situation. It is like you have seen a chair in a room and later return to take it. But the chair is not there anymore. Is it unexpected? The case should not be exceptional, IMO.

So we have:
1. Severity 1-10 "informational messages";
2. Severity 11-16 errors; and
3. RETURN error_code.

Which should be used? Anything else? Do my considerations make sense?

When I want the SQL Code to with certainly 'talk' back to the application code, I use RAISERROR.

For SQL Procedures to 'talk' with each other, I may also use the RETURN value.

I may use 'WITH LOG' to force the error condition into the Application Log.

And you are wise to question what is an error condition. Is it a 'system' error, a 'logic' error, or a 'business rule' exception?

|||Thank you, Arnie for sharing your experience.


> And you are wise to question what is an error condition. Is it a 'system'
> error, a 'logic' error, or a 'business rule' exception?

I believe that the "business logic" is an oxymoron likewise "market order", which is chaos and disorder in fact. Nevertheless, I do not distinguish between "rules" and "logic" here. It is logical that user balance should not go below zero, it is logical that the price must be the latest one, it is logical that user must belong to an existing group.

I understand the exceptions in a serial programing where your threads allocate (lock) resources but not in distributed programing where you cannot be sure about current condition of resources. It is ok for the local copies of the data to be incoherent in multiprocessor system. When data become incoherent, they may cause logic/rules/constraint/etc violations.

Some recommend checking file existence before opening it. But another process may remove the file between the check and open op. System returns "file does not exist" open error. It does not investigate whether the thread checked the file existence or it is making a reckless open. In other words, it does not examine the intentions and conditions of the caller. One utility would, for instance, set up admin rights for a list of users. This 'setadmin' app assumes the group 'admins' exists. It has nothing to do if there is no such group. It is exceptional situation for the app. Another application requests available groups, uses one and sends result back. Multiuser application should be prepared to situation where the used group does not exist anymore. A more realistic is a stock with multiple operators. When you have selected the list of available goods into a local copy, the goods can be removed by another operator.
You should tell the user that the product list is outdated, that it is incoherent with reality rather than complaining that the operation cannot be accomplished.

Looks like, error handling in distributed systems is more general than a DB errors issue. But any advices are welcomed.
|||

Valentin,

Note that I didn't use the term 'business logic', but instead used 'business rule exception' -and yet I agree with you that often business needs sometimes seem to defy logic; and that when describing the condition of a market, 'market order' could easily be a oxymoron, but when used as a entity, 'market order' has a definitive 'thing' quality about it.

This, and your other posts on Locking behavior demonstrate a deep concern for data integrity, and I can certainly appreciate your questions. When there are opportunities for instability, instability will occur. Stasis can only exist when ignoring temporality. Yet, in fact, Stasis cannot be separated from temporal considerations. The certainity of a state of data is increasingly uncertain as the system becomes more complex -distributed, multiprocessor, and multi-threaded. We often resort to extreme control when faced with apparant chaos. As TS Elliot would describe it, the time 'between' is the shadow, and we cannot ignore the shadow, for all things unknown exists in the shadow.

I once worked on a project where, for speed, data was cached on each web server in a very large web farm, and yet many data items were unique and ONLY one customer would be allowed to purchase that one item. There could be thousands of concurrent customers considering the same item. It was necessary to create a lot of communication between the cach objects, tenative 'sold' indicators, and definitive 'sold' indicators, 'cancellation', etc. You can imagine the chaos -but it did have a solution.

Since, as you put it so well, there are opportunities for chaos between the moment we determine IF an action can be taken AND the moment the action is actually taken, AND the 'system' doesn't help 'protect' us from that potential chaos, we are faced with having to find ways to invoke 'extreme control'. So like forcing all passengers through the security checkpoint as a single point of control, it may be useful to consider how to force all sensitive data activity through a 'single point of control'.

One useful approach is to force all data changes through Stored Procedures (No direct table access). Then in the Stored Procedure used to UPDATE a set of resouces in a TRANSACTION, also use sp_getapplock / sp_releaseapplock as a way to more tightly control access to the resources.

Here is an example: (Use Northwind database)

Code Snippet


CREATE PROCEDURE dbo.Employees_U_LastName
( @.EmployeeID int,
@.LastName varchar(20)
)
AS
BEGIN
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION


DECLARE @.LockResult int

EXECUTE @.LockResult = sp_getapplock
@.Resource = 'ThisIsMyProcess-StayOut',
@.LockMode = 'Exclusive',
@.LockTimeout = 0

IF @.LockResult <> 0
BEGIN
ROLLBACK TRANSACTION
PRINT 'SomeOne Else is Using this Resource'
RETURN
END


PRINT 'TRANSACTION IS Active'
SELECT
EmployeeID,
LastName,
FirstName
FROM Employees
WHERE EmployeeID = @.EmployeeID


PRINT 'Waiting...'
WAITFOR DELAY '00:00:15'

PRINT 'Second UPDATE to Active TRANSACTION'
UPDATE Employees
SET LastName = @.LastName
WHERE EmployeeID = @.EmployeeID


EXECUTE sp_releaseapplock
@.Resource = 'ThisIsMyProcess-StayOut'


COMMIT TRANSACTION


PRINT 'Waiting for Other Process to Complete'
WAITFOR DELAY '00:00:05'

PRINT 'CHECK Results of TRANSACTION'
SELECT
EmployeeID,
LastName,
FirstName
FROM Employees
WHERE EmployeeID = @.EmployeeID


END
GO

Then execute this from two different connections.

Code Snippet


EXECUTE dbo.Employees_U_LastName
@.EmployeeID = 1,
@.LastName = 'Davolio-Jones'

In the second connection, you will get the message: 'SomeOne Else is Using this Resource'. But you have to be adamant that there is only one 'egress' point to the resources -through the procedure.

Perhaps this will help you along on your quest to find a secure and reliable method to control data

|||

Sometimes maybe it doesn't matter if the 'problem' is a 'system' error, a 'logic' error, or a 'business rule' error -the 'problem' has to be handled, and in the case at hand, they may all be handled the same. It is still very useful to keep clarity about the differences between them. For at times, the effect of treating them the 'same' is confusing at best.

valentin tihomirov wrote:

I do not distinguish between "rules" and "logic" here. It is logical that user balance should not go below zero, it is logical that the price must be the latest one, it is logical that user must belong to an existing group.

Logic follows defined mathematical sylogisms.

1 = 2

2 = 3

Therefore 3 = 1

is based on logic. That balance MUST be >= 0 is a Business decision (busines rule) solely BECAUSE [ bal < 0 ] is mathematically valid -but in this situation, this business has determined to not allow that to occur. A bank 'should' not allow an account to overdraw (balance >= 0 ) at all times, in other words, as the trustee for your money, the bank 'should' not give others money claiming that it is your money if you don't have money to give out. However, the banking industry decided that there was money to be earned by allowing overdrafts, and you can't charge for an overdraft UNLESS the balance is allowed to be less than zero, so the business rule changed, and balance can be less than zero ( to some limit ).

Logic is easy to code, business rules, subject to change, require a lot more effort and consideration.

Of course, I realize that you know what I'm talking about. I'm using your posting to help others that may be reading, and still learning, and still uncertain... (So I hope you accept the 'lecture' in that guise. I often respond to a posting with the realization that I may also be responding to other readers with similar -but not exactly the same, questions.)

|||

For clarification, in the demonstration procedure I posted earlier, I used a PRINT statement when checking if @.LockResult. Normally, I would raise an error so that the calling application (or procedure) can capture the error number and react accordingly.

First, create the Error in the database, (Use whatever Error Number ( > 50000 ) and message you wish.)

Code Snippet

EXECUTE sp_addmessage
@.msgnum = 51001,
@.severity = 16,
@.msgtext = N'Resource NOT Available',
@.lang = 'us_english',
@.replace = REPLACE

Then in the procedure:

Code Snippet

IF @.LockResult <> 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR ( 51001, 16, 1 )
RETURN
END

Now the application (or calling procedure) can handle ErrorNumber 51001 as deemed necessary. Wait a few seconds and Re-Submit perhaps...

|||

Arnie Rowland wrote:

One useful approach is to force all data changes through Stored Procedures (No direct table access).

SPs are really how I'm trying to do it. Thanks for hinting about sp_getapplock. It looks like a 'lock' object (mutex, critical section) in conventional programming language. However, I think it is too coarse-grain. All the users who wish to change their last names will lock each other. In addition, this lock shell be taken by parties who affect the last names in different way (removing the record, for instance). And you get the whole database locked/synchronized by one big lock. The granularity of automatic transactional locks are one record. However, using full db object names like db_name.table_1.row_id.field_x we can outperform the locking granularity down to field finesse. These are my first ideas about the procedure. Thanks for the hint.

Arnie Rowland wrote:

Logic follows defined mathematical sylogisms.

I was learnt it is the math, which is a science of proving, which is based on logic But I think I can understand the difference between logic and rules now. Thank you for the explanation.

Arnie Rowland wrote:

Of course, I realize that you know what I'm talking about. I'm using your posting to help others that may be reading, and still learning, and still uncertain... (So I hope you accept the 'lecture' in that guise. I often respond to a posting with the realization that I may also be responding to other readers with similar -but not exactly the same, questions.)


That is ok, I am a communist. The sharing is a means of saving resources and a condition of intelligent life survival on the planet Earth.

|||

You're right, using sp_getapplock is kind of 'course-grained'; sp_getapplock creates a 'lock' object, using the name you provide. The only thing 'locked' is the entry to the sproc code. The included (and required) TRANSACTION locks the underlying data. However, blocking others from using the sproc code in practice creates a single 'gateway' through which all controlled activity must pass, effectively forcing serialization of the controlled activity. I would want to make the process as streamlined and efficient as possible in order to cause the minimal amount of queue stacking.

In a very high performance / high utilitzation system, using sp_getapplock just may prove to be to much of a 'bottleneck'. But, if one was concerned about reading into an active TRANSACTION, and the effects on other activities as a result of being able to read into an active TRANSACTION, sp_getapplock is one way to reduce the 'paranoia'. It may be too 'heavy-handed' for most use.

...deleted...

Keep up the good questions.

Business Object XI Variable Help

Hi All!

I am creating a report that lists every prescription a person is taking and the "Disease State" it is in. In the Group Header I need to list all the Disease States that this person is taking a prescription for. However, I cannot figure out how to do it.

In the details section, I have a formula for disease state. The person can be taking prescriptions for the same disease states. Therefore, the detail section could look like:
Diabetes
Diabetes
CHF
Diabetes

In the Group Header I need to output:
Diabetes, CHF

Does anyone know how to do this?
Thanks.
DanielleProbably the easiest way is to create a manual running total that will create a string containig unique disease states for each person. Then you can hide details and display person name and disease states in group footer.

Business Logic Object as Data Source in SQL Reporting Services

Hi all,
I'm running SQL Reporting Services and my question is:
Can I connect the datasource of my reports to a business logic object that
returns a dataset instead of using a direct connection to a SQL Server?
Anyone that knows if and how this can be done?
Regards
-Janne HasslfWhy didn't you post to the reportingsvcs newsgroup?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Janne" <janne.hasslof@.stenaline.com> wrote in message
news:70190248.0401290423.26d52934@.posting.google.com...
quote:

> Hi all,
> I'm running SQL Reporting Services and my question is:
> Can I connect the datasource of my reports to a business logic object that
> returns a dataset instead of using a direct connection to a SQL Server?
> Anyone that knows if and how this can be done?
> Regards
> -Janne Hasslf

Business Logic Object as Data Source in SQL Reporting Services

Hi all,
I'm running SQL Reporting Services and my question is:
Can I connect the datasource of my reports to a business logic object that
returns a dataset instead of using a direct connection to a SQL Server?
Anyone that knows if and how this can be done?do you have an OLE DB or .NET data provider to connect to BO?
-Aaron
Norberto Mesen Lopez wrote:
> Hi all,
> I'm running SQL Reporting Services and my question is:
> Can I connect the datasource of my reports to a business logic object that
> returns a dataset instead of using a direct connection to a SQL Server?
> Anyone that knows if and how this can be done?

Friday, February 10, 2012

BulkXMLload Error

Hi every now and again (i really can not replicate it) i get the following
error when trying to do a BulkXMLLoad:
"There is already an object named '__SQLXMLBulkload_1112988020_Snapshots' in
the database"
I'm inserting data into a table (called Snapshots) which has an Identity
column and i think this may have something to do with it.
Any help would be greatly appreciated
Jonny
Do you have more than one connection open doing bulkload? Looks like you
hit an issue in how we name temporary tables, getting a conflict because
bulkload is trying to create one that already exists. It is a known issue
we're fixing in SqlXml 4.0.
Irwin
"Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
news:d39jnv$l0h$1$8302bc10@.news.demon.co.uk...
> Hi every now and again (i really can not replicate it) i get the following
> error when trying to do a BulkXMLLoad:
> "There is already an object named '__SQLXMLBulkload_1112988020_Snapshots'
> in the database"
> I'm inserting data into a table (called Snapshots) which has an Identity
> column and i think this may have something to do with it.
> Any help would be greatly appreciated
> Jonny
>
|||Are you using Bulkload in a multhi-threaded environment?
Thanks.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
news:d39jnv$l0h$1$8302bc10@.news.demon.co.uk...
> Hi every now and again (i really can not replicate it) i get the following
> error when trying to do a BulkXMLLoad:
> "There is already an object named '__SQLXMLBulkload_1112988020_Snapshots'
in
> the database"
> I'm inserting data into a table (called Snapshots) which has an Identity
> column and i think this may have something to do with it.
> Any help would be greatly appreciated
> Jonny
>
|||Hi
I think i've found the problem.. Yes i was using it in a multi-threaded
environment and my critical section was initilised correctly
Thanks for the help
Jonny
"Bertan ARI [MSFT]" <bertan@.online.microsoft.com> wrote in message
news:uH1auguPFHA.4024@.TK2MSFTNGP10.phx.gbl...
> Are you using Bulkload in a multhi-threaded environment?
> Thanks.
> --
> Bertan ARI
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
> news:d39jnv$l0h$1$8302bc10@.news.demon.co.uk...
> in
>
|||Sorry that was meant to say "wasn't initilised correctly"
"Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
news:d3h19l$qgc$1$830fa7b3@.news.demon.co.uk...
> Hi
> I think i've found the problem.. Yes i was using it in a multi-threaded
> environment and my critical section was initilised correctly
> Thanks for the help
> Jonny
> "Bertan ARI [MSFT]" <bertan@.online.microsoft.com> wrote in message
> news:uH1auguPFHA.4024@.TK2MSFTNGP10.phx.gbl...
>

BulkXMLload Error

Hi every now and again (i really can not replicate it) i get the following
error when trying to do a BulkXMLLoad:
"There is already an object named '__SQLXMLBulkload_1112988020_Snapshots' in
the database"
I'm inserting data into a table (called Snapshots) which has an Identity
column and i think this may have something to do with it.
Any help would be greatly appreciated
JonnyDo you have more than one connection open doing bulkload? Looks like you
hit an issue in how we name temporary tables, getting a conflict because
bulkload is trying to create one that already exists. It is a known issue
we're fixing in SqlXml 4.0.
Irwin
"Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
news:d39jnv$l0h$1$8302bc10@.news.demon.co.uk...
> Hi every now and again (i really can not replicate it) i get the following
> error when trying to do a BulkXMLLoad:
> "There is already an object named '__SQLXMLBulkload_1112988020_Snapshots'
> in the database"
> I'm inserting data into a table (called Snapshots) which has an Identity
> column and i think this may have something to do with it.
> Any help would be greatly appreciated
> Jonny
>|||Are you using Bulkload in a multhi-threaded environment?
Thanks.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
news:d39jnv$l0h$1$8302bc10@.news.demon.co.uk...
> Hi every now and again (i really can not replicate it) i get the following
> error when trying to do a BulkXMLLoad:
> "There is already an object named '__SQLXMLBulkload_1112988020_Snapshots'[
/color]
in
> the database"
> I'm inserting data into a table (called Snapshots) which has an Identity
> column and i think this may have something to do with it.
> Any help would be greatly appreciated
> Jonny
>|||Hi
I think i've found the problem.. Yes i was using it in a multi-threaded
environment and my critical section was initilised correctly
Thanks for the help
Jonny
"Bertan ARI [MSFT]" <bertan@.online.microsoft.com> wrote in message
news:uH1auguPFHA.4024@.TK2MSFTNGP10.phx.gbl...
> Are you using Bulkload in a multhi-threaded environment?
> Thanks.
> --
> Bertan ARI
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
> news:d39jnv$l0h$1$8302bc10@.news.demon.co.uk...
> in
>|||Sorry that was meant to say "wasn't initilised correctly"
"Jonny" <jonny@.nospam.jonnywilk.co.uk> wrote in message
news:d3h19l$qgc$1$830fa7b3@.news.demon.co.uk...
> Hi
> I think i've found the problem.. Yes i was using it in a multi-threaded
> environment and my critical section was initilised correctly
> Thanks for the help
> Jonny
> "Bertan ARI [MSFT]" <bertan@.online.microsoft.com> wrote in message
> news:uH1auguPFHA.4024@.TK2MSFTNGP10.phx.gbl...
>

BulkLoad and .xsd problem

I would like to load a xml file to a database. For reasons this I use the
BulkLoad
COM object model. The elements of the project are following:
The XML file:
--
<?xml version="1.0" encoding="ISO8859-2" ?>
<export>
<ceg id="0000000147">
<rovat id = "0">
<alrovat id = "1">
<mezo id = "bir">piros</mezo>
<mezo id = "cf">tarka</mezo>
</alrovat>
</rovat>
<rovat id = "2">
<alrovat id = "1">
<mezo id = "nev">FA-MAG Ipari Kisszovetkezet</mezo>
</alrovat>
</rovat>
</ceg>
<ceg id="0000000153">
etc.
</ceg>
</export>
The columns of the tblExport table in the DB:
---
ceg_id char(10)
rovat_id varchar(10)
alrovat_id varchar(10)
mezo_id varchar(50)
mezo_text varchar(1000)
The following xsd file has been used:
--
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="ceg" sql:relation="[tblExport]">
<xsd:complexType>
<xsd:choice>
<xsd:element name="rovat" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="alrovat" minOccurs="0"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="mezo" sql:field="mezo_text"
minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="id"
sql:field="mezo_id" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" sql:field="alrovat_id"
type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" sql:field="rovat_id"
type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:attribute name="id" sql:field="ceg_id" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
I've expected the following result set (and I would like to get same):
ceg_id rovat_id alrovat_id mezo_id mezo
_text
----
0000000147 0 1 bir piros
0000000147 0 1 cf tarka
0000000147 2 1 nev FA-MAG Ipari Kisszovetkezet
0000000153 etc.
But I've got this:
ceg_id rovat_id alrovat_id mezo_id mezo
_text
----
0000000147 Null Null Null Null
0000000153 Null Null Null Null
etc.
Why? I tried to change the xsd file at many places and many times. For
example I changed <xsd:choice> to <xsd:sequence> but the BulkLoad
expected a reletionship on 'rovat'. But I don't want to take an extra table.
If I use sql:is-constant annotation an error will be raised saying that
constant element has no attribute. In most cases I don't get error but no
records will be generated.
Has anybody a good suggestion? I would be grateful for any help.
Thanks.
D. AttilaYou have to use xsd:sequence instead of xsd:choice and specify
sql:is-constant="1" on the elements 'rovat' and 'alrovat'.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
news:B08BA56A-FAD0-4DDE-A0B7-1FA57EA7C27B@.microsoft.com...
> I would like to load a xml file to a database. For reasons this I use the
> BulkLoad
> COM object model. The elements of the project are following:
> The XML file:
> --
> <?xml version="1.0" encoding="ISO8859-2" ?>
> <export>
> <ceg id="0000000147">
> <rovat id = "0">
> <alrovat id = "1">
> <mezo id = "bir">piros</mezo>
> <mezo id = "cf">tarka</mezo>
> </alrovat>
> </rovat>
> <rovat id = "2">
> <alrovat id = "1">
> <mezo id = "nev">FA-MAG Ipari Kisszovetkezet</mezo>
> </alrovat>
> </rovat>
> </ceg>
> <ceg id="0000000153">
> etc.
> </ceg>
> </export>
> The columns of the tblExport table in the DB:
> ---
> ceg_id char(10)
> rovat_id varchar(10)
> alrovat_id varchar(10)
> mezo_id varchar(50)
> mezo_text varchar(1000)
> The following xsd file has been used:
> --
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> <xsd:element name="ceg" sql:relation="[tblExport]">
> <xsd:complexType>
> <xsd:choice>
> <xsd:element name="rovat" minOccurs="0" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="alrovat" minOccurs="0"
> maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="mezo"
sql:field="mezo_text"
> minOccurs="0" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:attribute name="id"
> sql:field="mezo_id" type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="id" sql:field="alrovat_id"
> type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="id" sql:field="rovat_id"
> type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:choice>
> <xsd:attribute name="id" sql:field="ceg_id" type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
> I've expected the following result set (and I would like to get same):
> ceg_id rovat_id alrovat_id mezo_id mezo_text
> ----
> 0000000147 0 1 bir piros
> 0000000147 0 1 cf tarka
> 0000000147 2 1 nev FA-MAG Ipari Kisszovetkezet
> 0000000153 etc.
> But I've got this:
> ceg_id rovat_id alrovat_id mezo_id mezo_text
> ----
> 0000000147 Null Null Null Null
> 0000000153 Null Null Null Null
> etc.
> Why? I tried to change the xsd file at many places and many times. For
> example I changed <xsd:choice> to <xsd:sequence> but the BulkLoad
> expected a reletionship on 'rovat'. But I don't want to take an extra
table.
> If I use sql:is-constant annotation an error will be raised saying that
> constant element has no attribute. In most cases I don't get error but no
> records will be generated.
> Has anybody a good suggestion? I would be grateful for any help.
> Thanks.
> D. Attila
>
>|||Thanks, but I have tried it. I get the following error:
.....constant/fixed element cannot have attributes.....
But I need these attributes.
D.A.
"Bertan ARI [MSFT]" wrote:

> You have to use xsd:sequence instead of xsd:choice and specify
> sql:is-constant="1" on the elements 'rovat' and 'alrovat'.
> --
> Bertan ARI
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
> "Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
> news:B08BA56A-FAD0-4DDE-A0B7-1FA57EA7C27B@.microsoft.com...
> sql:field="mezo_text"
> table.
>
>|||Sorry my mistake. I didn't see the attributes.
Unfortunately, your scenario is currently not supported by Bulkload.
Currently we do not allow attributes on constant elements and there are no
future plans to support it.
You may use XSLT to transform the Xml into a shape Bulkload can support or
you may use OpenXml which doesn't have this limitation.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
news:CFB3D497-86E8-4207-97EA-F3EC42D2DEE5@.microsoft.com...
> Thanks, but I have tried it. I get the following error:
> .....constant/fixed element cannot have attributes.....
> But I need these attributes.
> D.A.
> "Bertan ARI [MSFT]" wrote:
>
rights.
the
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
maxOccurs="unbounded">
sql:field="alrovat_id"
/>
> ----
> ----
that
no|||Thanks for your response.
D.A.
"Bertan ARI [MSFT]" wrote:

> Sorry my mistake. I didn't see the attributes.
> Unfortunately, your scenario is currently not supported by Bulkload.
> Currently we do not allow attributes on constant elements and there are no
> future plans to support it.
> You may use XSLT to transform the Xml into a shape Bulkload can support or
> you may use OpenXml which doesn't have this limitation.
> --
> Bertan ARI
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
> "Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
> news:CFB3D497-86E8-4207-97EA-F3EC42D2DEE5@.microsoft.com...
> rights.
> the
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> maxOccurs="unbounded">
> sql:field="alrovat_id"
> />
> that
> no
>
>

BulkLoad and .xsd problem

I would like to load a xml file to a database. For reasons this I use the
BulkLoad
COM object model. The elements of the project are following:
The XML file:
<?xml version="1.0" encoding="ISO8859-2" ?>
<export>
<ceg id="0000000147">
<rovat id = "0">
<alrovat id = "1">
<mezo id = "bir">piros</mezo>
<mezo id = "cf">tarka</mezo>
</alrovat>
</rovat>
<rovat id = "2">
<alrovat id = "1">
<mezo id = "nev">FA-MAG Ipari Kisszovetkezet</mezo>
</alrovat>
</rovat>
</ceg>
<ceg id="0000000153">
etc.
</ceg>
</export>
The columns of the tblExport table in the DB:
ceg_idchar(10)
rovat_idvarchar(10)
alrovat_idvarchar(10)
mezo_idvarchar(50)
mezo_textvarchar(1000)
The following xsd file has been used:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:element name="ceg" sql:relation="[tblExport]">
<xsd:complexType>
<xsd:choice>
<xsd:element name="rovat" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="alrovat" minOccurs="0"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="mezo" sql:field="mezo_text"
minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="id"
sql:field="mezo_id" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" sql:field="alrovat_id"
type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" sql:field="rovat_id"
type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:attribute name="id" sql:field="ceg_id" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
I've expected the following result set (and I would like to get same):
ceg_idrovat_idalrovat_idmezo_idmezo_text
000000014701birpiros
000000014701cftarka
000000014721nevFA-MAG Ipari Kisszovetkezet
0000000153etc.
But I've got this:
ceg_idrovat_idalrovat_idmezo_idmezo_text
0000000147NullNullNullNull
0000000153NullNullNullNull
etc.
Why? I tried to change the xsd file at many places and many times. For
example I changed <xsd:choice> to <xsd:sequence> but the BulkLoad
expected a reletionship on 'rovat'. But I don't want to take an extra table.
If I use sql:is-constant annotation an error will be raised saying that
constant element has no attribute. In most cases I don't get error but no
records will be generated.
Has anybody a good suggestion? I would be grateful for any help.
Thanks.
D. Attila
You have to use xsd:sequence instead of xsd:choice and specify
sql:is-constant="1" on the elements 'rovat' and 'alrovat'.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
news:B08BA56A-FAD0-4DDE-A0B7-1FA57EA7C27B@.microsoft.com...
> I would like to load a xml file to a database. For reasons this I use the
> BulkLoad
> COM object model. The elements of the project are following:
> The XML file:
> --
> <?xml version="1.0" encoding="ISO8859-2" ?>
> <export>
> <ceg id="0000000147">
> <rovat id = "0">
> <alrovat id = "1">
> <mezo id = "bir">piros</mezo>
> <mezo id = "cf">tarka</mezo>
> </alrovat>
> </rovat>
> <rovat id = "2">
> <alrovat id = "1">
> <mezo id = "nev">FA-MAG Ipari Kisszovetkezet</mezo>
> </alrovat>
> </rovat>
> </ceg>
> <ceg id="0000000153">
> etc.
> </ceg>
> </export>
> The columns of the tblExport table in the DB:
> ceg_id char(10)
> rovat_id varchar(10)
> alrovat_id varchar(10)
> mezo_id varchar(50)
> mezo_text varchar(1000)
> The following xsd file has been used:
> --
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> <xsd:element name="ceg" sql:relation="[tblExport]">
> <xsd:complexType>
> <xsd:choice>
> <xsd:element name="rovat" minOccurs="0" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="alrovat" minOccurs="0"
> maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="mezo"
sql:field="mezo_text"
> minOccurs="0" maxOccurs="unbounded">
> <xsd:complexType>
> <xsd:attribute name="id"
> sql:field="mezo_id" type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="id" sql:field="alrovat_id"
> type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="id" sql:field="rovat_id"
> type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:choice>
> <xsd:attribute name="id" sql:field="ceg_id" type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
> I've expected the following result set (and I would like to get same):
> ceg_id rovat_id alrovat_id mezo_id mezo_text
> ----
> 0000000147 0 1 bir piros
> 0000000147 0 1 cf tarka
> 0000000147 2 1 nev FA-MAG Ipari Kisszovetkezet
> 0000000153 etc.
> But I've got this:
> ceg_id rovat_id alrovat_id mezo_id mezo_text
> ----
> 0000000147 Null Null Null Null
> 0000000153 Null Null Null Null
> etc.
> Why? I tried to change the xsd file at many places and many times. For
> example I changed <xsd:choice> to <xsd:sequence> but the BulkLoad
> expected a reletionship on 'rovat'. But I don't want to take an extra
table.
> If I use sql:is-constant annotation an error will be raised saying that
> constant element has no attribute. In most cases I don't get error but no
> records will be generated.
> Has anybody a good suggestion? I would be grateful for any help.
> Thanks.
> D. Attila
>
>
|||Thanks, but I have tried it. I get the following error:
......constant/fixed element cannot have attributes.....
But I need these attributes.
D.A.
"Bertan ARI [MSFT]" wrote:

> You have to use xsd:sequence instead of xsd:choice and specify
> sql:is-constant="1" on the elements 'rovat' and 'alrovat'.
> --
> Bertan ARI
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
> news:B08BA56A-FAD0-4DDE-A0B7-1FA57EA7C27B@.microsoft.com...
> sql:field="mezo_text"
> table.
>
>
|||Sorry my mistake. I didn't see the attributes.
Unfortunately, your scenario is currently not supported by Bulkload.
Currently we do not allow attributes on constant elements and there are no
future plans to support it.
You may use XSLT to transform the Xml into a shape Bulkload can support or
you may use OpenXml which doesn't have this limitation.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
news:CFB3D497-86E8-4207-97EA-F3EC42D2DEE5@.microsoft.com...[vbcol=seagreen]
> Thanks, but I have tried it. I get the following error:
> .....constant/fixed element cannot have attributes.....
> But I need these attributes.
> D.A.
> "Bertan ARI [MSFT]" wrote:
rights.[vbcol=seagreen]
the[vbcol=seagreen]
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">[vbcol=seagreen]
maxOccurs="unbounded">[vbcol=seagreen]
sql:field="alrovat_id"[vbcol=seagreen]
/>[vbcol=seagreen]
> ----
> ----
that[vbcol=seagreen]
no[vbcol=seagreen]
|||Thanks for your response.
D.A.
"Bertan ARI [MSFT]" wrote:

> Sorry my mistake. I didn't see the attributes.
> Unfortunately, your scenario is currently not supported by Bulkload.
> Currently we do not allow attributes on constant elements and there are no
> future plans to support it.
> You may use XSLT to transform the Xml into a shape Bulkload can support or
> you may use OpenXml which doesn't have this limitation.
> --
> Bertan ARI
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Danyi, Attila" <DanyiAttila@.discussions.microsoft.com> wrote in message
> news:CFB3D497-86E8-4207-97EA-F3EC42D2DEE5@.microsoft.com...
> rights.
> the
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> maxOccurs="unbounded">
> sql:field="alrovat_id"
> />
> that
> no
>
>