开发者

How to close sql server connection on completion when using powershell?

开发者 https://www.devze.com 2023-03-28 03:25 出处:网络
I am using the Sql Server powershell snapins (i.e. \"SqlServerProviderSnapin100\", \"SqlServerCmdletSnapin100\").I execute scripts using powershell, but when I try to execute them again, I get a \"No

I am using the Sql Server powershell snapins (i.e. "SqlServerProviderSnapin100", "SqlServerCmdletSnapin100"). I execute scripts using powershell, but when I try to execute them again, I get a "No process is on the other end of the pipe" shared memory error. I need to close Powershell, and restart it before it will work again.

It appe开发者_JAVA技巧ars that powershell is keeping a connection open, which is preventing the reexecution of the scripts.

Does anyone know how to solve this?

Thanks.


I found the answer.

The problem: The ADO connection pool is holding the connection once it is opened. Sql Server closes the connections, but the pool does not know of this, consequently, ADO assumes the connection is still valid, but it is not.

The solution: Execute [System.Data.SqlClient.SqlConnection]::ClearAllPools() first. This invalidates all connections that ADO is currently holding in the pool, and prevents the exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消