Answer the question
In order to leave comments, you need to log in
Is ADO.NET thread safe?
Is ADO.NET thread safe?
A simple query like:
Dim Connection As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConnectionSettings.ConnectionString)
Dim Command As System.Data.SqlClient.SqlCommand
Connection.Open()
Command = RequestBuilder.GetSomeData() 'тут заполняется commandtext и параметры запроса
Command.CommandTimeout = FCommandTimeout
Command.Connection = Connection
DataSetAdapter = New SqlClient.SqlDataAdapter(Command)
DS = New System.Data.DataSet("GetSomeData")
Try
DataSetAdapter.Fill(DS)
Finally
If Connection IsNot Nothing AndAlso Connection.State = ConnectionState.Open Then
Connection.Close()
End If
End Try
Answer the question
In order to leave comments, you need to log in
here below it says that ado.net is not thread-safe, except for reading from a dataset. So you really need to think about the distinctions
Since you are creating a new Connection each time, thread safety is fine.
Look for an error in RequestBuilder.GetSomeData()
Do you use temporary tables (#table) in your SQL query?
The fact is that temporary tables live within the same connection, and SQL Server, after closing the connection, does not kill it immediately, but keeps it for some time (this is done to increase performance). Thus, with frequent queries, SQL Server can give such a connection to all temporary tables ...
The way out of this situation is to delete everything from temporary tables in the SQL query if they exist.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question