使用powershell时如何在完成时关闭sql server连接?
我正在使用 Sql Server powershell 管理单元(即“SqlServerProviderSnapin100”、“SqlServerCmdletSnapin100”)。我使用 powershell 执行脚本,但是当我尝试再次执行它们时,出现“管道的另一端没有进程”共享内存错误。我需要关闭 Powershell,然后重新启动它才能再次工作。
powershell 似乎保持连接打开,这阻止了脚本的重新执行。
有谁知道如何解决这个问题?
谢谢。
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 appears that powershell is keeping a connection open, which is preventing the reexecution of the scripts.
Does anyone know how to solve this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。
问题:一旦连接打开,ADO 连接池就会保留该连接。 Sql Server 关闭连接,但池不知道这一点,因此,ADO 假定连接仍然有效,但事实并非如此。
解决方案:先执行[System.Data.SqlClient.SqlConnection]::ClearAllPools()。这将使 ADO 当前在池中保留的所有连接无效,并防止异常。
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.