REA_ANDREW
asked on
Connection must be closed first
Please could someone tell me why I am getting this error message?
Exception Details: MySql.Data.MySqlClient.MyS qlExceptio n: There is already an open DataReader associated with this Connection which must be closed first.
Source Error:
Line 35: MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(strSql, myConnection);
Line 36: DataSet myDataSet = new DataSet();
Line 37: myDataAdapter.Fill(myDataS et, "tbl_brands");
Line 38: brands_Dlist.DataSource = myDataSet;
Line 39: brands_Dlist.DataBind();
In my code I do nt have an open Connection at all, although I must be doing something wrong, but it is driving me crazy. Thanks in advance and here is my complete code.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
using System.Web.UI.HtmlControls ;
using MySql.Data.MySqlClient;
public partial class Default5 : System.Web.UI.Page
{
MySqlConnection myConnection = new MySqlConnection("server=lo calhost; user id=andy; password=xxxxxxxxx; database=penny_lane_taking s; pooling=false;");
public int Shop1Ind = 0;
public int Shop2Ind = 0;
public String IntSql;
public DateTime SysT = new DateTime();
protected void Page_Load(object sender, EventArgs e)
{
SysT = DateTime.Now.Date;
SysToday.InnerHtml = "Today: "+String.Format("{0:D}", SysT);
String strSql = "SELECT takings_date FROM days_takings WHERE shopname = 'shop1' AND takings_date ='" + SysT + "'";
myConnection.Open();
DataSet shop1DS = new DataSet();
//if (shop1DS.Tables["days_taki ngs"].Rows .Count == 0)
MySqlDataAdapter shop1DA = new MySqlDataAdapter(strSql, myConnection);
shop1DA.Fill(shop1DS, "days_takings");
myConnection.Close();
//LoadData();
}
}
Exception Details: MySql.Data.MySqlClient.MyS
Source Error:
Line 35: MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(strSql, myConnection);
Line 36: DataSet myDataSet = new DataSet();
Line 37: myDataAdapter.Fill(myDataS
Line 38: brands_Dlist.DataSource = myDataSet;
Line 39: brands_Dlist.DataBind();
In my code I do nt have an open Connection at all, although I must be doing something wrong, but it is driving me crazy. Thanks in advance and here is my complete code.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
using MySql.Data.MySqlClient;
public partial class Default5 : System.Web.UI.Page
{
MySqlConnection myConnection = new MySqlConnection("server=lo
public int Shop1Ind = 0;
public int Shop2Ind = 0;
public String IntSql;
public DateTime SysT = new DateTime();
protected void Page_Load(object sender, EventArgs e)
{
SysT = DateTime.Now.Date;
SysToday.InnerHtml = "Today: "+String.Format("{0:D}", SysT);
String strSql = "SELECT takings_date FROM days_takings WHERE shopname = 'shop1' AND takings_date ='" + SysT + "'";
myConnection.Open();
DataSet shop1DS = new DataSet();
//if (shop1DS.Tables["days_taki
MySqlDataAdapter shop1DA = new MySqlDataAdapter(strSql, myConnection);
shop1DA.Fill(shop1DS, "days_takings");
myConnection.Close();
//LoadData();
}
}
can you try running your code with the myConnection.Open();. You new code should look like this:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
using System.Web.UI.HtmlControls ;
using MySql.Data.MySqlClient;
public partial class Default5 : System.Web.UI.Page
{
MySqlConnection myConnection = new MySqlConnection("server=lo calhost; user id=andy; password=xxxxxxxxx; database=penny_lane_taking s; pooling=false;");
public int Shop1Ind = 0;
public int Shop2Ind = 0;
public String IntSql;
public DateTime SysT = new DateTime();
protected void Page_Load(object sender, EventArgs e)
{
SysT = DateTime.Now.Date;
SysToday.InnerHtml = "Today: "+String.Format("{0:D}", SysT);
String strSql = "SELECT takings_date FROM days_takings WHERE shopname = 'shop1' AND takings_date ='" + SysT + "'";
//myConnection.Open();
DataSet shop1DS = new DataSet();
//if (shop1DS.Tables["days_taki ngs"].Rows .Count == 0)
MySqlDataAdapter shop1DA = new MySqlDataAdapter(strSql, myConnection);
shop1DA.Fill(shop1DS, "days_takings");
//myConnection.Close();
//LoadData();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using System.Web.UI.HtmlControls
using MySql.Data.MySqlClient;
public partial class Default5 : System.Web.UI.Page
{
MySqlConnection myConnection = new MySqlConnection("server=lo
public int Shop1Ind = 0;
public int Shop2Ind = 0;
public String IntSql;
public DateTime SysT = new DateTime();
protected void Page_Load(object sender, EventArgs e)
{
SysT = DateTime.Now.Date;
SysToday.InnerHtml = "Today: "+String.Format("{0:D}", SysT);
String strSql = "SELECT takings_date FROM days_takings WHERE shopname = 'shop1' AND takings_date ='" + SysT + "'";
//myConnection.Open();
DataSet shop1DS = new DataSet();
//if (shop1DS.Tables["days_taki
MySqlDataAdapter shop1DA = new MySqlDataAdapter(strSql, myConnection);
shop1DA.Fill(shop1DS, "days_takings");
//myConnection.Close();
//LoadData();
}
}
ASKER
I still get the same error
try:
myConnection.Close();
myConnection.Dispose();
myConnection.Close();
myConnection.Dispose();
myConnection.Open();
Dont do this before you adapter.
The adapater will open its self. Its does NOT need the open or the close. This is all handled by the adapter.
Dont do this before you adapter.
The adapater will open its self. Its does NOT need the open or the close. This is all handled by the adapter.
can u try pasting this whole code in a new vb file and try to run it again. It could be possible that this error is occuring it some other place but VS is showing it at this location. VS does do this some time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Exception Details: MySql.Data.MySqlClient.MyS
Source Error:
Line 27: //if (shop1DS.Tables["days_taki
Line 28: MySqlDataAdapter shop1DA = new MySqlDataAdapter(strSql, myConnection);
Line 29: shop1DA.Fill(shop1DS, "days_takings");
Line 30: myConnection.Close();
Line 31: //LoadData();
Source File: d:\home\Default\nwcms.co.u