SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
I use multiple threads for insert operation, but an error will occur at some time. Is it because all threads share a SqlConnection? How to solve it?
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
I use multiple threads for insert operation, but an error will occur at some time. Is it because all threads share a SqlConnection? How to solve it?
Simply use a new SqlConnection for each operation and have the connection string available for each in a central variable.
Maybe it is not a problem that is caused by SqlConnection only. Show the error message and details.
Do not share connections among multiple threads.
Create a SqlConnection object for each of your queries, and wrap it with a using statement to close it in time after the execution ends.
.NET, the SqlConnection object, and multi-threading
Using the same open SQL connection from different threads
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
10 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?