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
AdditionalMethod(data)
Commit Tran
Close Conn
}
AdditionalMethod(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 AdditionalMethod
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*****@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP15.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