473,699 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlTransaction problem???

Hi all
I have a master-detail tables in sql server.
I use SqlTransaction to insert data into both tables.
it works well but if I check the "Cascade Delete Related Records" option in
it's realtion in sql server my SqlTransaction dosen't work and get timeout
error..

please help me
thanks in advance
Dec 2 '05 #1
4 2897
There are so many factors that could be causing this

- What kind of locks are you generally getting on your table - are they
page locks? Is the pk index clustered?
- What exactly is your update logic like? DataAdapter.Upd ate will only
affect one single table, so how exactly are you getting master-detail to
work?
- Does this happen in concurrent scenarios or single user scenarios?
- Is it unpredictable in general?
- other reasons ..

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
----------------------------------------------------------------------------
"perspolis" <re*****@hotmai l.com> wrote in message
news:uV******** ******@TK2MSFTN GP15.phx.gbl...
Hi all
I have a master-detail tables in sql server.
I use SqlTransaction to insert data into both tables.
it works well but if I check the "Cascade Delete Related Records" option
in
it's realtion in sql server my SqlTransaction dosen't work and get timeout
error..

please help me
thanks in advance

Dec 2 '05 #2
You don't mention if you are using DataAdaptors etc, so I'm going to
assuming you are (like me) rigging your own Sql using the ADO.NET command,
connection and transaction objects directly...

If you are getting a timeout error doing a delete (of any kind, but
especially cascading), there are two big causes:

1: your delete is going on a killing spree and is just taking a long time
because deleting 1 header record means deleting 2134245 detail records
2: (more likely) you are getting consistently blocked

So - if you are getting this behaviour consistently it seems likely that you
are, in fact, blocking yourself. Do you have any other open connections (and
more importantly, transactions) operating on this data from the same client?
Are you perhaps doing multiple (nested) transactional sql calls on different
transactions?

e.g. (in pseudo code)

Delete(data) {
Create Conn
Begin Tran
Call SP1 for data on the above conn/tran
AdditionalMetho d(data)
Commit Tran
Close Conn
}

AdditionalMetho d(data) {
Create Conn
Begin Tran
Call SP2 for data on the above conn/tran
Commit Tran
Close Conn
}

The above layout will inevitably block when attempting SP2 because SP1 has
the locks, and isn't going to release them until the Commit Tran in
Delete(); Since you are using Sql-Server, when you execute your code, and
before the timeout fires (try upping it for debugging), you should be able
to use sp_who in the database to see who is blocking you (look for a
non-zero entry in the blk column, and then find the row with that value in
the spid column); probably the login and host on the offending row are
yours. If the blocking spid is 82 (for instance) you can then call dbcc
inputbuffer(82) to see what the last command executed on that connection
was.

If your situation is anything like the above, the solution (obviously) is to
ensure that both the calls execute on the same transaction, for instance by
passing the transaction as a parameter to the AdditionalMetho d

Of course it could also be that somebody else with access to the database
has just left their transaction open for 5 hours ;-p (easily done if you are
debugging something in T-SQL and then go to a long meeting...)

Marc

"perspolis" <re*****@hotmai l.com> wrote in message
news:uV******** ******@TK2MSFTN GP15.phx.gbl...
Hi all
I have a master-detail tables in sql server.
I use SqlTransaction to insert data into both tables.
it works well but if I check the "Cascade Delete Related Records" option
in
it's realtion in sql server my SqlTransaction dosen't work and get timeout
error..

please help me
thanks in advance

Dec 2 '05 #3
Hi
I used it in single session and I call SqlDataAdaptor for tow tables first
Master then Details and my pk is clustered..
and I use the BeginTransatcio n of SqlConnection with default
mode(Serialaiza ble)..

"Sahil Malik [MVP C#]" <co************ *****@nospam.co m> wrote in message
news:e5******** *****@TK2MSFTNG P10.phx.gbl...
There are so many factors that could be causing this

- What kind of locks are you generally getting on your table - are they
page locks? Is the pk index clustered?
- What exactly is your update logic like? DataAdapter.Upd ate will only
affect one single table, so how exactly are you getting master-detail to
work?
- Does this happen in concurrent scenarios or single user scenarios?
- Is it unpredictable in general?
- other reasons ..

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
-------------------------------------------------------------------------- --

"perspolis" <re*****@hotmai l.com> wrote in message
news:uV******** ******@TK2MSFTN GP15.phx.gbl...
Hi all
I have a master-detail tables in sql server.
I use SqlTransaction to insert data into both tables.
it works well but if I check the "Cascade Delete Related Records" option
in
it's realtion in sql server my SqlTransaction dosen't work and get timeout error..

please help me
thanks in advance


Dec 2 '05 #4
Okay that clarifies a bit.

First of all, the default mode(I think you meant isolation level) is
ReadCommitted for both SQL Server and Oracle - not Serializable.

Secondly, this approach won't work. When you start working with hierarchical
data, you need to add rows from the parent table first, followed by adding
the relevant child rows. Updates need to follow adds, because you could both
add a new master row, and modify a detail row to use the FK of the newly
added row. But updates need to follow the same path Master->Detail. Deletes
however need to follow the reverse path, or you will simply get FK errors,
because details need to be removed before the master can be.

Not only that, in this scenario, you would have the delete page locks
causing locks with inserts and updates page locks, and if you lock too much,
the db may end up locking tables - so essentially you cannot predict what
transactions cause locks in what.

So what do you do?

Well obviously, you need a different persistence mechanism, my book's
chapter 10 explains dealing with hierarchical data in detail. But in short,
you need to respect the relationships in your persistence mechanism - in
addition to rowstates. A few things you could try are using non clustered
indexes, and controlling the connection opening yourself rather than having
the dataadapter do it for you. That *may* help :), but not necessarily in
all situations. Search my blog for "Pessimisti c locking is your friend" for
a detailed explanation on the ideal solution for hierarchical data. That
pretty much describes the ferrari approach - the mostest perfectestest
solution. But you may just be okay with a Honda. Anyway, there is more to
this than I can type right now in a newsgroup reply, but I gave you some
pointers to poke around on :)

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
----------------------------------------------------------------------------
"perspolis" <re*****@hotmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi
I used it in single session and I call SqlDataAdaptor for tow tables first
Master then Details and my pk is clustered..
and I use the BeginTransatcio n of SqlConnection with default
mode(Serialaiza ble)..

"Sahil Malik [MVP C#]" <co************ *****@nospam.co m> wrote in message
news:e5******** *****@TK2MSFTNG P10.phx.gbl...
There are so many factors that could be causing this

- What kind of locks are you generally getting on your table - are they
page locks? Is the pk index clustered?
- What exactly is your update logic like? DataAdapter.Upd ate will only
affect one single table, so how exactly are you getting master-detail to
work?
- Does this happen in concurrent scenarios or single user scenarios?
- Is it unpredictable in general?
- other reasons ..

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
--------------------------------------------------------------------------

--


"perspolis" <re*****@hotmai l.com> wrote in message
news:uV******** ******@TK2MSFTN GP15.phx.gbl...
> Hi all
> I have a master-detail tables in sql server.
> I use SqlTransaction to insert data into both tables.
> it works well but if I check the "Cascade Delete Related Records"
> option
> in
> it's realtion in sql server my SqlTransaction dosen't work and get timeout > error..
>
> please help me
> thanks in advance
>
>



Dec 2 '05 #5

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

Similar topics

2
2054
by: mahajan.sanjeev | last post by:
I have two SQLConnection objects having the same connection string and two corresponding SQLCommand objects for each connection object. I am using SQLTransaction with the first SQLConnection object but the second SQLConnection object does not have any SQLTransaction object. I am inserting some data using the two command objects. The problem happens when I try to do a rollback on the SQLTransaction object. The rollback happens only before...
2
2804
by: mahajan.sanjeev | last post by:
Hi, I am having problems with rollback using the SQLTransaction object. I am trying to insert records in two tables in a transaction. I want to rollback all the changes if any exception occurs in any of the inserts. But the SQLTransaction object only rolls back the inserts that happen before an exception. All inserts after the exception go through. What am I doing wrong? Is it that I cannot do any more Inserts using the transaction...
0
1079
by: mahajan.sanjeev | last post by:
Hi All, I am using a SQLTransaction in a .Net application to insert records into a SQL Server table. At one time, there are 5000 or more records to be inserted one by one. It takes some 20-25 mins for the entire process to run. Another application accesses the same table. As long as the insert process within the transaction isn't completed,
0
1502
by: perspolis | last post by:
Hi all I used SqlTransaction inmy application.. SqlTransaction transact=sqlConnection1.BeginTransaction(IsoLationLevel.Something); sqlSelect.Transaction=transact; sqlInsert.Transaction=transact; ,............... but any of IsolationLevel stat I use it dosen't work properly and it works as Serializable isolation level.. When I'm using a transaction for a master-slave tables and I want when
2
2767
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the information into three separate tables (all in a single aspx page -- without using stored procedures, yet). The first SQL Statement accepts the persons most detailed information, like name, address, phone, etc and inserts the single record into...
0
1033
by: Joe Rigley | last post by:
Hi All, I am using a SqlTransaction object to process a group of database insert / update statements on Sql Server 200 SP4 to complete a business process. Directly after the Commit method is issued, I perform a select on one of the tables that was inserted into during the SqlTransaction process. Unfortunately, the select statement does not return any data that was just inserted. I have checked the SQL statement syntax and it is valid....
5
451
by: Swami Muthuvelu | last post by:
Hi, I using command builder to generate my insert, update and delete statements..something like, data_adapter = New SqlClient.SqlDataAdapter(SQL, ActiveConnection) command_builder = New SqlClient.SqlCommandBuilder (data_adapter)
3
1294
by: Neven Klofutar | last post by:
Hi, I'm trying to retrieve some information from DB using SqlTransaction, but I have a problem. I'm executing some DELETE SQL statements using Transaction. Then later on (because of the lousy project) I need to read the same information from DB that is beeing deleted using the same transaction. Is it possible to delete data, and read the same data in one SqlTransaction, or that Transaction cannot read the data anymore even if Commit()...
3
3127
MrMancunian
by: MrMancunian | last post by:
Ok, I'm stuck on a design problem and I need some feedback how to go around it. CASE: Pathologists can request stains on certain tissues. It's possible to request more than one stain a time. The program where they make these requests (which is third-party software) creates an XML-file for one stain. So, if two stains are requested on one piece of tissue, it will create two XML-files. The program I'm writing needs to parse those XML-files,...
0
8686
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8615
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9173
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7748
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6533
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.