sql server - Conn.Open() still work after SQL Service is stopped -
i have met issue sql server 2005 sp2, have created windows form , button on it, , following steps:
- make sure sql service running, click button, ok
- stop sql service, , click button again, on machine, there not exception @ code of line 1, exception occurred @ line 2, , exception info:
message: transport-level error has occurred when sending request server. (provider: shared memory provider, error: 0 - no process on other end of pipe.)
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.data.sqlclient; namespace reconnectsql { public partial class form1 : form { private string m_connectionstring = @"server=(local); database=testdb; user id=sa; password=admins; connection timeout=15"; public form1() { initializecomponent(); } /// <summary> /// /// </summary> public datatable getbyfilldatatable() { try { sqlcommand cmd = new sqlcommand("getalldata"); cmd.commandtype = commandtype.storedprocedure; datatable dt = this.getdatatable(cmd); return dt; } catch { throw; } } #region common funcs /// <summary> /// /// </summary> /// <param name="cmd"></param> /// <returns></returns> private datatable getdatatable(sqlcommand cmd) { datatable dt = new datatable(); using (sqlconnection conn = new sqlconnection(this.m_connectionstring)) { try { conn.open(); // line 1 } catch (exception ex) { throw; } using (sqldataadapter adapter = new sqldataadapter()) { try { cmd.connection = conn; cmd.commandtimeout = conn.connectiontimeout; adapter.selectcommand = cmd; adapter.fill(dt); // line 2 } catch (exception ex) { throw; } } } return dt; } #endregion private void button2_click(object sender, eventargs e) { try { datatable dt = getbyfilldatatable(); listbox1.items.add("getbyfilldatatable called without exceptions!"); } catch (exception ex) { listbox1.items.add(ex.message); } } } }
detailed exception info:
- [system.data.sqlclient.sqlexception] {"a transport-level error has occurred when sending request server. (provider: shared memory provider, error: 0 - no process on other end of pipe.)"} system.data.sqlclient.sqlexception + base {"a transport-level error has occurred when sending request server. (provider: shared memory provider, error: 0 - no process on other end of pipe.)"} system.data.common.dbexception {system.data.sqlclient.sqlexception} class 20 byte + errors {system.data.sqlclient.sqlerrorcollection} system.data.sqlclient.sqlerrorcollection linenumber 0 int number 233 int procedure null string server "(local)" string source ".net sqlclient data provider" string state 0 byte
stacktrace
at system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection) @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection) @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj) @ system.data.sqlclient.tdsparserstateobject.writesni() @ system.data.sqlclient.tdsparserstateobject.writepacket(byte flushmode) @ system.data.sqlclient.tdsparserstateobject.executeflush() @ system.data.sqlclient.tdsparser.tdsexecuterpc(_sqlrpc[] rpcarray, int32 timeout, boolean inschema, sqlnotificationrequest notificationrequest, tdsparserstateobject stateobj, boolean iscommandproc) @ system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async) @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, dbasyncresult result) @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method) @ system.data.sqlclient.sqlcommand.executereader(commandbehavior behavior, string method) @ system.data.sqlclient.sqlcommand.executedbdatareader(commandbehavior behavior) @ system.data.common.dbcommand.system.data.idbcommand.executereader(commandbehavior behavior) @ system.data.common.dbdataadapter.fillinternal(dataset dataset, datatable[] datatables, int32 startrecord, int32 maxrecords, string srctable, idbcommand command, commandbehavior behavior) @ system.data.common.dbdataadapter.fill(datatable[] datatables, int32 startrecord, int32 maxrecords, idbcommand command, commandbehavior behavior) @ system.data.common.dbdataadapter.fill(datatable datatable) @ reconnectsql.form1.getdatatable(sqlcommand cmd) in e:\_public_\sqlfail\reconnectsql\reconnectsql\form1.cs:line 138
after investigations, seems connection still exist in connection pool sql stopped, after sql started , calling conn.open() connection object pool should invalid, sqldataadapter.fill cause exception
Comments
Post a Comment