A
Amit D.Shinde
Hello
I have on clsGlobal.cs File in which i have created many functions of
Fetching, Inserting Data In Database.. Using Ado.net AsP.net C#.net
Those Functions returns String, Dataset etc.
But NO WHERE I AM USING DATAREADER IN WHOLE PROJECT.
But i Get the Error While at a time two users logs in i.e. more than
one user try to access my webapplication.
The error is as follows:
"There is already an open DataReader associated with this Connection
which must be closed first. "
I know why this error occurs .. .due to not closing of connection but
everywhere i am closing the connection ..
Please Help Me i am sending some samples where error occurss..
public static DataSet ExecuteSPDS(SqlCommand pCmd)
{
DataSet sResult;
try
{
SqlDataAdapter da = new SqlDataAdapter(pCmd);
DataSet ds = new DataSet();
da.Fill(ds,"RECORD");
sResult = ds;
}
catch(System.Exception ex)
{
sResult = null;
}
return sResult;
}
========================================================
public static string ExecuteScalarQuery1(string query)
{
string Result;
//try
{
SqlCommand cmd = new SqlCommand(query,m_Connection);
if(m_Connection.State==ConnectionState.Closed)
{
m_Connection.Open();
}
Result=Convert.ToString(cmd.ExecuteScalar());
if(m_Connection.State==ConnectionState.Open)
{
m_Connection.Close();
}
//catch(System.Exception ex)
{
}
return Result;
}
}
====================================================
I have on clsGlobal.cs File in which i have created many functions of
Fetching, Inserting Data In Database.. Using Ado.net AsP.net C#.net
Those Functions returns String, Dataset etc.
But NO WHERE I AM USING DATAREADER IN WHOLE PROJECT.
But i Get the Error While at a time two users logs in i.e. more than
one user try to access my webapplication.
The error is as follows:
"There is already an open DataReader associated with this Connection
which must be closed first. "
I know why this error occurs .. .due to not closing of connection but
everywhere i am closing the connection ..
Please Help Me i am sending some samples where error occurss..
public static DataSet ExecuteSPDS(SqlCommand pCmd)
{
DataSet sResult;
try
{
SqlDataAdapter da = new SqlDataAdapter(pCmd);
DataSet ds = new DataSet();
da.Fill(ds,"RECORD");
sResult = ds;
}
catch(System.Exception ex)
{
sResult = null;
}
return sResult;
}
========================================================
public static string ExecuteScalarQuery1(string query)
{
string Result;
//try
{
SqlCommand cmd = new SqlCommand(query,m_Connection);
if(m_Connection.State==ConnectionState.Closed)
{
m_Connection.Open();
}
Result=Convert.ToString(cmd.ExecuteScalar());
if(m_Connection.State==ConnectionState.Open)
{
m_Connection.Close();
}
//catch(System.Exception ex)
{
}
return Result;
}
}
====================================================