New sql connection for each request?

I am writing a server application that communicates with a local SQL server.

Each client will need to read or write data to the database.

Would it be better to have a thread safe class that will run and execute sql commands in a single sql connection? Or do I need to open a new connection for each team? Is it important for performance?

+3
source share
3 answers

If you have a batch of statements that must be executed one after another, you must use the same SqlConnection. Once you do not need SqlConnection, and you do not know when you need a connection, you must close the connection.

, insert update , , SqlConnection.
, , . .

, . , , . , DbCommand.

+6

- ADO.NET, ( , SQL Server), , - .

- .

+6

Usually you need to create a new connection for each command and use the built-in connection pool.

+2
source

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


All Articles