Opening two SQLConnections with the same ConnectionString

I am tracking a bug in a library that I have not written myself. When using this library with ASP.NET, I get db connection errors because the SQLConnection seems to be closed when the second connection opens with the same connection string.

Is this documented behavior? Can open a new SQLConnection with the same connection string to close another SQLConnection object?

Debugging, which seems to be the most likely cause of my problems, but I could not find anything on the Internet to support my theory.

+4
source share
3 answers

No, it happens that when you call the SqlConnection.Open() , even with the same connection string parameters, it performs one of two tasks: either reuse an unused connection from the pool, or create a new connection. In any case, you will get conflict-free SPIDs for SQL Server.

+3
source

Is this documented behavior?

No.

Can opening a new SQLConnection with the same connection string close another SQLConnection object?

No.

Note that if you have not changed the settings, SQL Server allows 32,767 concurrent connections. But even then, this would not explain the behavior you see.

+3
source

In short, opening a new connection with the same connection string will not close the existing connection. However ... reusing an existing object by creating a new link to a new connection will destroy the connection.

0
source

Source: https://habr.com/ru/post/1387046/


All Articles