打开后ADO Connection仍然连接? [英] ADO Connection still connecting after Open?

查看:90
本文介绍了打开后ADO Connection仍然连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本周突然间,我开始收到此错误消息:


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

解决方案

亲爱的布莱斯,

我在Windows XP SP2,C#2.0,SQL Server 2005中尝试了与您相同的代码

并且工作正常。因为它突然停止了一些可能导致这个问题的事情(这些只是我的猜测)

1)多个连接/连接池问题

2)任何其他进程/线程做同样的事情


另外如果你在

之前检查连接状态ExecuteReader(),你得到了什么?


-

希望这会有所帮助!


Y. Sivaram

" Bryce K. Nielsen" <峰; br *** @ sysonyx.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP04.phx.gbl ...

突然这一周,我开始收到此错误消息:

System.Data.SqlClient.SqlConnection(GetOpenConnect ion)ExecuteNonQuery
需要一个开放且可用的连接。连接的当前状态是
连接。

我很困惑,因为我没有打电话给ExecuteNonQuery。我正在打电话
打开,我一直认为它是同步的,即在A)连接打开或B)出现错误之前不会返回
。这是有效的我在做什么:

SqlConnection SourceServer =新的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



" Bryce K. Nielsen" <峰; br *** @ sysonyx.com>写在

新闻:#


************** @ TK2MSFTNGP04.phx.gbl:
< blockquote class =post_quotes>本周突然间,我开始收到此错误消息:

System.Data.SqlClient.SqlConnection(GetOpenConnect ion)ExecuteNonQ
uery需要打开并且可用连接。连接的当前状态正在连接。

我非常困惑,因为我没有打电话给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上发生了这个错误。有没有其他人经历过这个?你有什么办法来解决这个问题?




布莱斯,


这听起来像是竞争条件。


您的应用程序是否有多个线程调用此代码?


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)ExecuteNonQuery
requires an open and available Connection. The connection''s current state is
connecting.

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 return
until either A) the connection was open or B) there was an error. Here is
effectively 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 else
experiencing this? And what have you done to solve this?

-BKN

解决方案

Dear Bryce,

I tried the same code as yours in Windows XP SP2, C# 2.0, SQL Server 2005
and it worked fine. As it has stopped all of a sudden some of the things
that could have caused this issue are (These are just my guesses)
1) Multiple connections/connection pooling issues
2) Any other process/thread doing the same

Also if you check the state of the connection just before the
ExecuteReader(), what do you get?

--
Hope this helps!

Y. Sivaram
"Bryce K. Nielsen" <br***@sysonyx.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

Suddenly this week, I''ve started getting this error message:

System.Data.SqlClient.SqlConnection(GetOpenConnect ion)ExecuteNonQuery
requires an open and available Connection. The connection''s current state
is
connecting.

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 return
until either A) the connection was open or B) there was an error. Here is
effectively 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 else
experiencing this? And what have you done to solve this?

-BKN



"Bryce K. Nielsen" <br***@sysonyx.com> wrote in
news:#


**************@TK2MSFTNGP04.phx.gbl:

Suddenly this week, I''ve started getting this error message:

System.Data.SqlClient.SqlConnection(GetOpenConnect ion)ExecuteNonQ
uery requires an open and available Connection. The connection''s
current state is connecting.

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 return until either A) the connection was open or
B) there was an error. Here is effectively 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
else experiencing this? And what have you done to solve this?



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仍然连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆