c# - Sql Server 2008 Closing Connections after database dropped -
I left a database and was rebuilt and next time I'm having trouble leaving the connection to SQL Server Try to execute an order against a new connection on the same database, I am getting:
A transport-level error occurred while sending a request to the server (Provider: Shared memory provider, Error: 0 - There is no process on the other end of the pipe.)
Here is the TCP version (if I try to connect to another server)
A transport-level error generated when sending a request to the server Hui. (Provider: TCP provider, Error: 0 - An existing connection was forcibly closed by remote host.)
These steps are taken to restore the problem:
- Open a connection to a database and execute a sql command
- Drop the database
- Rebuild the database
- One Open a new connection from the database
Result: I get an exception
Here's the code:
C; (var Conn = new System.Data.SqlClient.SqlConnection ("Data Source = Initial Catalog = DBNAME; Integrated Security = True")) {conn.Open (); Var cmd = conn.CreateCommand (); Cmd.CommandText = "UPDATE ..."; Cmd.ExecuteNonQuery (); } String SQL = "Database DBManet with Dual-set Single-User Rollback with Instant Drop Database"; Var Server = New Microsoft.SqlServer.Management.Smo.Server ("."); Server.ConnectionContext.ExecuteNonQuery (SQL); Server.ConnectionContext.Disconnect (); Sql = file Read all the text ("Pathotodsfilefile ..."); Server = New Microsoft.SqlServer.Management.Smo.Server ("."); Server.ConnectionContext.ExecuteNonQuery (SQL); Server.ConnectionContext.Disconnect (); (Var conn = new System.Data.SqlClient.SqlConnection ("Data source =. Initial catalog = WER_CONFIG; coordinated security = true")) (conn.Open (); var cmd = conn.CreateCommand (); Cmd.CommandText = "UPDATE ..."; cmd.ExecuteNonQuery ();} The error occurs at the very end of the 'cmd.ExecuteNonQuery ()' line. It appears that even if I Every time I connect, I'm creating a new connection, SQL Server keeps some (or possibly Adonet code) views, where next time I ask for a connection, it gives me one Which is already used or has been turned off on the server side.
Note that if I do not do this then it has been turned off on the server (probably due to that database This is being omitted).
The first step to execute the initial query, and I just leave the database, make it again, and execute an order, I did not get this error I think that from the database. Establishing initial connection is an important part of this error.
I have also tried to use an external process that can recreate and reproduce the database:
ProcessStartInfo info = new ProcessStartInfo ("sqlcmd .exe "," -eE -S--Q "" restore database DBNAME set instant drop database with single-user rollback DBMNA \ "); Var p = Process Start (notification); P.WaitForExit (); Info = New ProcessStart Infos ("sqlcmd.exe", "-i" + Pathotodsfilefile); P = Process Start (info); P.WaitForExit (); And this did not help.
Is there a way to create a new SQL connection and is it sure that it is not from the pool? Any other suggestions about solving this problem?
Update: The problem was solved by using SqlConnection.ClearPool (), but I just decided to edit my connection string with pooling = false, whatever worked. You can try to stop this behavior by adding pooling = false as a parameter to your connection string.
Comments
Post a Comment