I m 书写一个服务器应用程序,与当地一台ql服务器通信。
每个客户都需要阅读或书写数据库的数据。
是否最好有一个可怕的安全等级,它将在单一ql接线上排列和执行 s的指挥? 或者,我是否为每一指挥部打开新的联系? 这是否对业绩很重要?
I m 书写一个服务器应用程序,与当地一台ql服务器通信。
每个客户都需要阅读或书写数据库的数据。
是否最好有一个可怕的安全等级,它将在单一ql接线上排列和执行 s的指挥? 或者,我是否为每一指挥部打开新的联系? 这是否对业绩很重要?
If you have a batch of statements that have to be executed after each other, you should use the same SqlConnection. As soon as you do not longer need the SqlConnection, and you do not know when you will need a connection again, you should close the connection.
So, if you have to execute 2 insert statements and one update statement after each other, for instance, you should use the same SqlConnection.
The most important advantage here, is that you can put those statement in a transaction if necessary. Transactions cannot be shared accross connections.
When you re finished working with the DB, you can close the connection. By default, connection pooling is used, and the connection will be returned to the pool, so that it can be reused the next time you need a connection to the DB. Connection lifetime should be short, but you should not use a separate connection for each DbCommand.
如果你使用ADO的任何碎片。 该网络将自动使用连接(至少与Kall服务器)除非你明确加以区别,因此没有理由在这方面做任何特殊的事情。
保证在每次使用后都保持你的联系,这只会使连接点重新连接。
通常,你应为每一指挥部建立新的联系,并利用内在的连接。