473,516 Members | 3,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebService, SQL Server 2005 and Updating rows with relations?

Hi,

I have a MSSQL 2005 test DB with two tables:

Table "T1Customers":

T1CustomersRowEnum (PK, int, Not Null)
T1CustomersFullName (nvarchar(50) null)

Table "T2Details":

T2DetailsRowEnum (PK, int, Not Null)
T1CustomersRowEnum (FK, int, not null)
T2DetailsAddress (nvarchar(50), null
Also at the SQL Server I have set a "Diagram" so "FK_T2Details_T1Customers"
in relation and "Cascade" for Update & Delete.
The Problem:
A client application is generating a DataSet on a file and send it to a Web
Service that will call the dataset file and make a batch update to the DB.
I have created a dataset XML with relation & "Cascade" for it.

The XML:

<DataSet1 xmlns="http://tempuri.org/DataSet1.xsd">
<xs:schema id="DataSet1" targetNamespace="http://tempuri.org/DataSet1.xsd"
xmlns:mstns="http://tempuri.org/DataSet1.xsd"
xmlns="http://tempuri.org/DataSet1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="DataSet1" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="T1Customers">
<xs:complexType>
<xs:sequence>
<xs:element name="T1CustomersRowEnum" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int"/>
<xs:element name="T1CustomersFullName" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="T2Details">
<xs:complexType>
<xs:sequence>
<xs:element name="T2DetailsRowEnum" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int"/>
<xs:element name="T1CustomersRowEnum" type="xs:int" minOccurs="0"/>
<xs:element name="T2DetailsAddress" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:T1Customers"/>
<xs:field xpath="mstns:T1CustomersRowEnum"/>
</xs:unique>
<xs:unique name="T2Details_Constraint1"
msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:T2Details"/>
<xs:field xpath="mstns:T2DetailsRowEnum"/>
</xs:unique>
<xs:keyref name="FK_T2Details_T1Customers" refer="Constraint1">
<xs:selector xpath=".//mstns:T2Details"/>
<xs:field xpath="mstns:T1CustomersRowEnum"/>
</xs:keyref>
</xs:element>
</xs:schema>
<T1Customers>
<T1CustomersRowEnum>0</T1CustomersRowEnum>
<T1CustomersFullName>ABC</T1CustomersFullName>
</T1Customers>
<T2Details>
<T2DetailsRowEnum>0</T2DetailsRowEnum>
<T1CustomersRowEnum>0</T1CustomersRowEnum>
<T2DetailsAddress>123</T2DetailsAddress>
</T2Details>
</DataSet1>

When trying to run below code I am getting the error:

The INSERT statement conflicted with the FOREIGN KEY constraint
"FK_T2Details_T1Customers". The conflict occurred in database "Test2", table
"dbo.T1Customers", column 'T1CustomersRowEnum'. The statement has been
terminated
The code:

DataSet1 ds = new DataSet1();
ds.ReadXml(@"C:\NewData.xml", XmlReadMode.IgnoreSchema);

T1CustomersTableAdapter objT1CustomersTableAdapter = new
T1CustomersTableAdapter();
T2DetailsTableAdapter objT2DetailsTableAdapter = new
T2DetailsTableAdapter();

objT1CustomersTableAdapter.Update(ds.T1Customers);
objT2DetailsTableAdapter.Update(ds.T2Details);

The very same code & very same XML dataset on a "Windows Application"
project is working fine.

Why it is not working on a web service?

Thanks in advanced for any help.
Regards,
Asaf

Mar 1 '06 #1
3 1507
Hi Asafl,

Thanks for posting.

From your description, you're building an ASP.NET webservice which accepts
some DataSet from the client consumer, and use ADO.NET TableAdapter to
update the DataSet into backend database. However, you found that it will
fail into some SQL related error , and the code used to work in normal
winform application, correct?

As you mentioned the code worked in winform application, so I think the
overall code logic should be ok. So far I think we can check the following
things:

1. When the DataSet is transfered to webservice server-side, we can check
whether the two table and records are correctly stored in it( the same as
when it is in winform application). particularly, we can check the
DataRow's Status in the DataTable, this will affect the processing when we
call Update method on DataSet.

2. At SQL Server side, we can also use profiler to monitor the processing
of the dataset's updating. From the error message, the error conerned with
constraint confliction. I think it is likely that the first parent record
is not correctly inserted so that when the sequential sub record is being
inserted, there occur the error.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Mar 2 '06 #2
Hi Steven,

I have solved the problem using other programming methods.

Thanks for your help.
Asaf
"Steven Cheng[MSFT]" wrote:
Hi Asafl,

Thanks for posting.

From your description, you're building an ASP.NET webservice which accepts
some DataSet from the client consumer, and use ADO.NET TableAdapter to
update the DataSet into backend database. However, you found that it will
fail into some SQL related error , and the code used to work in normal
winform application, correct?

As you mentioned the code worked in winform application, so I think the
overall code logic should be ok. So far I think we can check the following
things:

1. When the DataSet is transfered to webservice server-side, we can check
whether the two table and records are correctly stored in it( the same as
when it is in winform application). particularly, we can check the
DataRow's Status in the DataTable, this will affect the processing when we
call Update method on DataSet.

2. At SQL Server side, we can also use profiler to monitor the processing
of the dataset's updating. From the error message, the error conerned with
constraint confliction. I think it is likely that the first parent record
is not correctly inserted so that when the sequential sub record is being
inserted, there occur the error.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights

Mar 2 '06 #3
Thanks for your followup Asaf,

Glad that you've found the way to go on.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Mar 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
9290
by: Adam Short | last post by:
I am trying to write a routine that will connect a .NET server with a classic ASP server. I know the following code doesn't work! The data is being returned as a dataset, however ASP does not recognise datasets and requires a recordset. Can the datatypes be converted? At the Classic ASP end or .NET end? Can SOAP toolkit provide the...
2
1428
by: William Cleveland | last post by:
I'm working on a system right now where I have a database (two, actually, but one is discarded halfway through), but it's created and used as part of a process (reporting), rather than as the actual production data repository. I may be keeping the database permanantly, but it would be completely read-only; once the process is complete, the...
1
1931
by: James | last post by:
All data for my company is stored on an internet web server, hosted by discountasp.net, and a web service is used for both Windows and web clients to retreive and modify it. I'm using a Microsoft Access .mdb file. A local server is not used because, although only a small business, not all employees work from a single location (some in London,...
14
2104
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
5
2615
by: Corno | last post by:
Hi all, If I want to provide a typed dataset from a webservice and if that dataset has relations that are nested (isNested=True), then the relations(keyrefs) are not available in the XSD that is offered. If I set IsNested to false or default, then it is included in the XSD. Is this a bug or by design? Corno
9
1715
by: Mr Newbie | last post by:
HI People, Thanks to all who helped me earlier on the subject of @@IDentity. However, I seem to have hit another snagette! My DataSet contains two tables from the SQL Server. lets say Master and Details. The way I have it set up is that a relationship exists in the DataSet between the two to force referential integrety etc. I am now...
6
1556
by: kenneth fleckenstein nielsen | last post by:
Hi guru's It runs ok on my developmaschine, and on the test server that i've set up. but fails after installing on the customers server. I made a XML webservice that does these steps: a) access a db for updating ( fails on client ) b) saves some associated files (DIMES/SOAP) ( not testet outside development ) c) writes a log file ( fails on...
6
3837
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called "Generations"), and it allows the user to add, edit and delete the various records of the table. "Generations" table has the following fields: "IDPerson",...
0
1720
by: kolalakitty | last post by:
Hopefully someone here can help me/point me in the right direction. I've found tons of references towards making relations, creating rows, saving said rows, using datagrids, databinding objects, and etc in regards to Windows Forms, C#, and Visual Studio .Net 2003. I seem to have run into a bit of a problem however. I'm not using datagrids...
0
7273
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7405
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7574
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3265
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.