|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Aborting a thread corrupts my SqlConnection (?)I'm running a long query in a separate thread. If I abort that thread and then I try to use the same connection string again, I get an unexpected result. Details: the aborted thread runs a query that returns a resultset, using a DataAdapter. the query run afterwards is: INSERT INTO Report_selection_ids DEFAULT VALUES; SELECT SCOPE_IDENTITY() which usually returns an integer, but if executed after the resultset query thread was killed, it returns what seems to be the 1st field of the 1st record of the recordset, which happens to be a string. I've seen posts on a similar problem in framework 1.0, which was supposed to be fixed long ago. I'm using framework 1.1 (no SP - is there one?) thx Uri
Show quote
Hide quote
"Uri Dor" <tablul@newsgroups.nospam> wrote in message Yes, there is sp1.news:u8LU0it1EHA.3336@TK2MSFTNGP11.phx.gbl... > Hi, > I'm running a long query in a separate thread. If I abort that thread and > then I try to use the same connection string again, I get an unexpected > result. > Details: > > the aborted thread runs a query that returns a resultset, using a > DataAdapter. > the query run afterwards is: > INSERT INTO Report_selection_ids DEFAULT VALUES; SELECT SCOPE_IDENTITY() > > which usually returns an integer, but if executed after the resultset > query thread was killed, it returns what seems to be the 1st field of the > 1st record of the recordset, which happens to be a string. > > I've seen posts on a similar problem in framework 1.0, which was supposed > to be fixed long ago. > > I'm using framework 1.1 (no SP - is there one?) However, you really shouldn't kill threads - rather use sync mechanisms to signal to thread to finish. Btw, how exactly are you killing the thread? Are you creating a new instance of conneciton object for the new query? -- Miha Markic [MVP C#] - RightHand .NET consulting & development SLODUG - Slovene Developer Users Group www.rthand.com Thanks for your reply, Miha.
I installed sp1, but the problem is still reproducible. I'm killing the thread using Thread.Abort() and treating the exception. I'm not aware of any sync mechanism that can stop a SqlDataAdapter.Fill() call - are you? Regarding the connections - the killed thread uses its own SqlConnection instance, although it uses the same connection string so it's pooled. What's the standard way to do such a thing - basically, to call DataAdapter.Fill and then interrupt it? Miha Markic [MVP C#] wrote: Show quoteHide quote > "Uri Dor" <tablul@newsgroups.nospam> wrote in message > news:u8LU0it1EHA.3336@TK2MSFTNGP11.phx.gbl... > >>Hi, >>I'm running a long query in a separate thread. If I abort that thread and >>then I try to use the same connection string again, I get an unexpected >>result. >>Details: >> >>the aborted thread runs a query that returns a resultset, using a >>DataAdapter. >>the query run afterwards is: >>INSERT INTO Report_selection_ids DEFAULT VALUES; SELECT SCOPE_IDENTITY() >> >>which usually returns an integer, but if executed after the resultset >>query thread was killed, it returns what seems to be the 1st field of the >>1st record of the recordset, which happens to be a string. >> >>I've seen posts on a similar problem in framework 1.0, which was supposed >>to be fixed long ago. >> >>I'm using framework 1.1 (no SP - is there one?) > > > Yes, there is sp1. > However, you really shouldn't kill threads - rather use sync mechanisms to > signal to thread to finish. > Btw, how exactly are you killing the thread? > Are you creating a new instance of conneciton object for the new query? > "Uri Dor" <tablul@newsgroups.nospam> wrote in message No, there aren't.news:eIwgJR31EHA.208@TK2MSFTNGP12.phx.gbl... > Thanks for your reply, Miha. > I installed sp1, but the problem is still reproducible. > I'm killing the thread using Thread.Abort() and treating the exception. > I'm not aware of any sync mechanism that can stop a SqlDataAdapter.Fill() > call - are you? However, you might throw an exception within RowChanged event (I am not sure if this would stop the Fill process though). > Regarding the connections - the killed thread uses its own SqlConnection Interesting.> instance, although it uses the same connection string so it's pooled. > Try the suggestion above and see what happens and let us know.> What's the standard way to do such a thing - basically, to call > DataAdapter.Fill and then interrupt it? -- Miha Markic [MVP C#] - RightHand .NET consulting & development SLODUG - Slovene Developer Users Group www.rthand.com Killing a thread is always dangerous. If at all possible you should avoid
doing that. One option for the Fill case is to try to use the Cancel() method in the command object (adapter.SelectCommand.Cancel()). Depending on where the command processing is, it may help. -- Show quoteHide quotePablo Castro Program Manager - ADO.NET Team Microsoft Corp. This posting is provided "AS IS" with no warranties, and confers no rights. "Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:OvyOkP41EHA.3368@TK2MSFTNGP10.phx.gbl... > > "Uri Dor" <tablul@newsgroups.nospam> wrote in message > news:eIwgJR31EHA.208@TK2MSFTNGP12.phx.gbl... > > Thanks for your reply, Miha. > > I installed sp1, but the problem is still reproducible. > > I'm killing the thread using Thread.Abort() and treating the exception. > > I'm not aware of any sync mechanism that can stop a SqlDataAdapter.Fill() > > call - are you? > > No, there aren't. > However, you might throw an exception within RowChanged event (I am not sure > if this would stop the Fill process though). > > > Regarding the connections - the killed thread uses its own SqlConnection > > instance, although it uses the same connection string so it's pooled. > > Interesting. > > > > What's the standard way to do such a thing - basically, to call > > DataAdapter.Fill and then interrupt it? > > Try the suggestion above and see what happens and let us know. > > -- > Miha Markic [MVP C#] - RightHand .NET consulting & development > SLODUG - Slovene Developer Users Group > www.rthand.com > >
Other interesting topics
Removing rows from a DataTable is VERY slow
Specifying format of DateTime columns read from CSV files DataSet Memory Usage SQLDataReader data adapter update using datatable that has MANY changes Evaluating Reporting Tools for .NET Storing passwords in database Encrypting/Decrypting Connection String Problem copying datatable-long post populating dataset from excel range, error where no data. |
|||||||||||||||||||||||