本文介绍了打开后ADO Connection仍然连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 本周突然间,我开始收到此错误消息: System.Data.SqlClient.SqlConnection(GetOpenConnect ion)ExecuteNonQuery 需要一个开放的可用连接。连接的当前状态是 连接。 我很困惑,因为我没有打电话给ExecuteNonQuery。我打电话给 打开,我一直认为这是同步的,即不会返回 ,直到A)连接打开或B)有一个错误。这是有效的我在做什么: SqlConnection SourceServer = new SqlConnection(SourceConnectionString); SourceServer.Open() ; SqlCommand sourcecmd = new SqlCommand(); sourcecmd.Connection = SourceServer; sourcecmd.CommandType = CommandType.StoredProcedure ; sourcecmd.CommandText =" sp" + TableName +" Select"; sourcecmd.CommandTimeout = 1800; sourcecmd.Parameters.Add(" myid",SqlDbType.Int).Value = MyId; SqlDataReader read = sourcecmd.ExecuteReader(); 这个错误发生在ExecuteReader上。其他人 遇到这个?你有什么办法来解决这个问题? -BKN 解决方案 布莱斯, 这听起来像是竞争条件。 您的应用程序是否有多个线程调用此代码? Chris。 ---------- --- CR Timmons Consulting,Inc。 http: //www.crtimmonsinc.com/ Suddenly this week, I''ve started getting this error message:System.Data.SqlClient.SqlConnection(GetOpenConnect ion)ExecuteNonQueryrequires an open and available Connection. The connection''s current state isconnecting.I''m very puzzled since I''m not calling "ExecuteNonQuery" and I am calling"Open", which I''ve always assumed was Synchronous, i.e. would not returnuntil either A) the connection was open or B) there was an error. Here iseffectively what I am doing:SqlConnection SourceServer = new SqlConnection(SourceConnectionString);SourceServer.Open();SqlCommand sourcecmd = new SqlCommand();sourcecmd.Connection = SourceServer;sourcecmd.CommandType = CommandType.StoredProcedure;sourcecmd.CommandText = "sp" + TableName + "Select";sourcecmd.CommandTimeout = 1800;sourcecmd.Parameters.Add("myid", SqlDbType.Int).Value = MyId;SqlDataReader read = sourcecmd.ExecuteReader();It''s on that ExecuteReader that this error is happening. Anyone elseexperiencing this? And what have you done to solve this?-BKN 解决方案Bryce,This sounds like a race condition.Does your app have multiple threads calling this code?Chris.-------------C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/ 这篇关于打开后ADO Connection仍然连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 07:54