我的连接字符串如下所示,在我的Web.config中:
<connectionStrings>
<clear />
<add name="Northwind_DB" connectionString="Data Source=dataSource; Initial Catalog=initialCatalog; MultipleActiveResultSets=True; Persist Security Info=True; User ID=userID; Password=password;" providerName="System.Data.SqlClient" />
</connectionStrings>
正如您所看到的,我的ConnectionStrings中有MultipleActiveResultSets = True,但我仍然收到错误&#34;该连接不支持MultipleActiveResultSets&#34;在尝试运行我的代码时。
以下是抛出错误的代码:
SqlConnection Conn;
SqlCommand Command1 = new SqlCommand();
SqlCommand Command2 = new SqlCommand();
SqlDataReader Reader1;
SqlDataReader Reader2;
IAsyncResult ASyncResult1;
IAsyncResult AsyncResult2;
System.Threading.WaitHandle[] WHandles = new
System.Threading.WaitHandle[2];
System.Threading.WaitHandle WHandle1;
System.Threading.WaitHandle WHandle2;
Conn = new SqlConnection();
Conn.ConnectionString =
ConfigurationManager.ConnectionStrings["Northwind_DB"].ConnectionString;
Command1.CommandText = "SQL statement is here.";
Command1.CommandType = CommandType.Text;
Command1.Connection = Conn;
Command2.CommandText = "SQL statement is here";
Command2.CommandType = CommandType.Text;
Command2.Connection = Conn;
Conn.Open();
AsyncResult1 = CustCommand.BeginExecuteReader();
ASyncResult2 = OrdersCommand.BeginExecuteReader();
WHandle1 = AsyncResult1.AsyncWaitHandle;
WHandle2 = ASyncResult2.AsyncWaitHandle;
WHandles[0] = WHandle1;
WHandles[1] = WHandle2;
System.Threading.WaitHandle.WaitAll(WHandles);
DataReader1 = Command1.EndExecuteReader(AsyncResult1);
DataReader2 = Command2.EndExecuteReader(ASyncResult2);
gvData1.DataSource = Reader1;
gvData1.DataBind();
gvData2.DataSource = Reader2;
gvData2.DataBind();
Conn.Close();
我不确定导致此代码失败的原因是什么,在我的代码中启用多个活动结果集时我做错了什么?我最初得到的答案是将它放在我网站上各种其他线程的ConnectionString中,但不幸的是,它对我没用。