I am using SqlTransaction
s in my code for roll back purpose. Within the transaction I got multiple statements to be executed with may include selects inserts and updates. All these statements are within the scope of the sqltransaction
. Everything works fine just for one problem. I am using datareader
s for select statements . And these readers are closed once they are used. This forces the connection to be lost and every thing fails. Does any one have a solution on whether I can use datareader
s within a sqltransaction
??
相关问题
- Sorting 3 numbers without branching [closed]
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Graphics.DrawImage() - Throws out of memory except
- Difference between Types.INTEGER and Types.NULL in
You should open the SqlConnection by itself.
The SqlDataReader doesn't close the SqlConnection when you close the DataReader
For example:
A DataReader will only close the connection if the
CommandBehavior.CloseConnection
option was set when callingExecuteReader
.You should be OK if you avoid setting this option.