I was facing a problem with one of the PowerShell function that I wrote using System.Data.SqlClient.SQLConnection, that with the first run it works, but with subsequent runs it fails with error
Exception calling “ExecuteNonQuery” with “0” argument(s): “A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 1 – I/O Error detected in read/write operation)”
And in other machines , the error was with TCP/IP and Named Pipes too.
Well, as I did not changed anything in my environment my first step was not to look at the SQL Protocols or TCP chimney..etc. Should be other issue .
For some reason, there is a connectivity problem with a previously opened session in SQL Server, then to fix it, you just need to clear the connection pool :
My code was :
Added : [System.Data.SqlClient.SqlConnection]::ClearAllPools()