473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET 1.1 datareader already opened : conflict between users

Hi,

{asp .net 1.1, sp 2)

I am facing problems with multi users accessing the same page. There is a
datagrid in the webform. The "datareader already opened error/ object
reference not found" errors will occur randomly when multi users are
clicking page number (paging), any page number.

The connection object is declared private and connection is closed
immediately after fill command. I am testing using two separate machines and
clicking the page number simultaneously.

Thanks.

Following is the snippet of the data access layer :

////////////////////////////////////////////////////////////
/////// base class - abstract

/////////////////////////////////////////////////////////////

public abstract class DbObject

{

private SqlConnection Connection;

private string connectionString;

public DbObject( string newConnectionString )

{

connectionString = newConnectionString;

Connection = new SqlConnection( connectionString );

}

protected DataSet RunProcedure(string storedProcName, IDataParameter[]
parameters, string tableName )

{

try

{

DataSet ds = new DataSet();

Connection.Open();

SqlDataAdapter sqlDA = new SqlDataAdapter();

sqlDA.SelectCommand = BuildQueryCommand( storedProcName, parameters );

sqlDA.Fill( dataSet, tableName );

return ds;

}

finally

{

if (Connection.State == ConnectionState.Open) Connection.Close();

}

}

/////////////////////////////////////////////////////////////////

The data class :

/////////////////////////////////////////////////////////////////

public class SqlProductController : DbObject,
Modules.Product.DAL.IProductController

{

private int appID;

public SqlProductController(string newConnectionString, int
appID):base(newConnectionString){ this.appID = appID;}

public DataSet GetProductList(string SearchText, int ID)

{

SqlParameter[] parameters = { new SqlParameter("@SearchText",
SqlDbType.NVarChar, 1000),

new SqlParameter("@PartnerId", SqlDbType.Int, 4) };

parameters[0].Value = SearchText;

parameters[1].Value = ID;
try

{

return RunProcedure("sp_SearchProdList", parameters, "ProductList");

}

catch (SqlException e)

{

throw new AppException("An error executing the Product_GetProdList
method", e );

}

}

}


Aug 6 '06 #1
3 1399
I'm sure you didn't close the reader. May be it throw exception before
closing the reader, always use try - catch - finally when use Datareader..
You can always Check connectionstate in the finally code block and close it.

"jason" <ll****@excite.comwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
Hi,

{asp .net 1.1, sp 2)

I am facing problems with multi users accessing the same page. There is a
datagrid in the webform. The "datareader already opened error/ object
reference not found" errors will occur randomly when multi users are
clicking page number (paging), any page number.

The connection object is declared private and connection is closed
immediately after fill command. I am testing using two separate machines
and clicking the page number simultaneously.

Thanks.

Following is the snippet of the data access layer :

////////////////////////////////////////////////////////////
/////// base class - abstract

/////////////////////////////////////////////////////////////

public abstract class DbObject

{

private SqlConnection Connection;

private string connectionString;

public DbObject( string newConnectionString )

{

connectionString = newConnectionString;

Connection = new SqlConnection( connectionString );

}

protected DataSet RunProcedure(string storedProcName, IDataParameter[]
parameters, string tableName )

{

try

{

DataSet ds = new DataSet();

Connection.Open();

SqlDataAdapter sqlDA = new SqlDataAdapter();

sqlDA.SelectCommand = BuildQueryCommand( storedProcName, parameters );

sqlDA.Fill( dataSet, tableName );

return ds;

}

finally

{

if (Connection.State == ConnectionState.Open) Connection.Close();

}

}

/////////////////////////////////////////////////////////////////

The data class :

/////////////////////////////////////////////////////////////////

public class SqlProductController : DbObject,
Modules.Product.DAL.IProductController

{

private int appID;

public SqlProductController(string newConnectionString, int
appID):base(newConnectionString){ this.appID = appID;}

public DataSet GetProductList(string SearchText, int ID)

{

SqlParameter[] parameters = { new SqlParameter("@SearchText",
SqlDbType.NVarChar, 1000),

new SqlParameter("@PartnerId", SqlDbType.Int, 4) };

parameters[0].Value = SearchText;

parameters[1].Value = ID;
try

{

return RunProcedure("sp_SearchProdList", parameters, "ProductList");

}

catch (SqlException e)

{

throw new AppException("An error executing the Product_GetProdList
method", e );

}

}

}


Aug 6 '06 #2
thank you Islamegy

As you can see in my code, I did use try except finally to close the
connection, and the connection is not shared. I am not using DataReader
directly either, I guess the DataAdapter is using DataReader internally to
access DB, correctly me if i am wrong.

Just couldn't figure out what went wrong, as this supposed to be a straight
forward code.


"Islamegy®" <Is******@Private.4mewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I'm sure you didn't close the reader. May be it throw exception before
closing the reader, always use try - catch - finally when use Datareader..
You can always Check connectionstate in the finally code block and close
it.

"jason" <ll****@excite.comwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
>Hi,

{asp .net 1.1, sp 2)

I am facing problems with multi users accessing the same page. There is a
datagrid in the webform. The "datareader already opened error/ object
reference not found" errors will occur randomly when multi users are
clicking page number (paging), any page number.

The connection object is declared private and connection is closed
immediately after fill command. I am testing using two separate machines
and clicking the page number simultaneously.

Thanks.

Following is the snippet of the data access layer :

////////////////////////////////////////////////////////////
/////// base class - abstract

/////////////////////////////////////////////////////////////

public abstract class DbObject

{

private SqlConnection Connection;

private string connectionString;

public DbObject( string newConnectionString )

{

connectionString = newConnectionString;

Connection = new SqlConnection( connectionString );

}

protected DataSet RunProcedure(string storedProcName, IDataParameter[]
parameters, string tableName )

{

try

{

DataSet ds = new DataSet();

Connection.Open();

SqlDataAdapter sqlDA = new SqlDataAdapter();

sqlDA.SelectCommand = BuildQueryCommand( storedProcName, parameters );

sqlDA.Fill( dataSet, tableName );

return ds;

}

finally

{

if (Connection.State == ConnectionState.Open) Connection.Close();

}

}

/////////////////////////////////////////////////////////////////

The data class :

/////////////////////////////////////////////////////////////////

public class SqlProductController : DbObject,
Modules.Product.DAL.IProductController

{

private int appID;

public SqlProductController(string newConnectionString, int
appID):base(newConnectionString){ this.appID = appID;}

public DataSet GetProductList(string SearchText, int ID)

{

SqlParameter[] parameters = { new SqlParameter("@SearchText",
SqlDbType.NVarChar, 1000),

new SqlParameter("@PartnerId", SqlDbType.Int, 4) };

parameters[0].Value = SearchText;

parameters[1].Value = ID;
try

{

return RunProcedure("sp_SearchProdList", parameters, "ProductList");

}

catch (SqlException e)

{

throw new AppException("An error executing the
Product_GetProdList method", e );

}

}

}



Aug 7 '06 #3
problem solved....

one of the base class controller was declared as static.

Thanks.
"jason" <ll****@excite.comwrote in message
news:uG**************@TK2MSFTNGP02.phx.gbl...
thank you Islamegy

As you can see in my code, I did use try except finally to close the
connection, and the connection is not shared. I am not using DataReader
directly either, I guess the DataAdapter is using DataReader internally to
access DB, correctly me if i am wrong.

Just couldn't figure out what went wrong, as this supposed to be a
straight forward code.


"Islamegy®" <Is******@Private.4mewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I'm sure you didn't close the reader. May be it throw exception before
closing the reader, always use try - catch - finally when use
Datareader..
You can always Check connectionstate in the finally code block and close
it.

"jason" <ll****@excite.comwrote in message
news:ue**************@TK2MSFTNGP02.phx.gbl...
>>Hi,

{asp .net 1.1, sp 2)

I am facing problems with multi users accessing the same page. There is
a datagrid in the webform. The "datareader already opened error/ object
reference not found" errors will occur randomly when multi users are
clicking page number (paging), any page number.

The connection object is declared private and connection is closed
immediately after fill command. I am testing using two separate machines
and clicking the page number simultaneously.

Thanks.

Following is the snippet of the data access layer :

////////////////////////////////////////////////////////////
/////// base class - abstract

/////////////////////////////////////////////////////////////

public abstract class DbObject

{

private SqlConnection Connection;

private string connectionString;

public DbObject( string newConnectionString )

{

connectionString = newConnectionString;

Connection = new SqlConnection( connectionString );

}

protected DataSet RunProcedure(string storedProcName, IDataParameter[]
parameters, string tableName )

{

try

{

DataSet ds = new DataSet();

Connection.Open();

SqlDataAdapter sqlDA = new SqlDataAdapter();

sqlDA.SelectCommand = BuildQueryCommand( storedProcName, parameters );

sqlDA.Fill( dataSet, tableName );

return ds;

}

finally

{

if (Connection.State == ConnectionState.Open) Connection.Close();

}

}

/////////////////////////////////////////////////////////////////

The data class :

/////////////////////////////////////////////////////////////////

public class SqlProductController : DbObject,
Modules.Product.DAL.IProductController

{

private int appID;

public SqlProductController(string newConnectionString, int
appID):base(newConnectionString){ this.appID = appID;}

public DataSet GetProductList(string SearchText, int ID)

{

SqlParameter[] parameters = { new SqlParameter("@SearchText",
SqlDbType.NVarChar, 1000),

new SqlParameter("@PartnerId", SqlDbType.Int, 4) };

parameters[0].Value = SearchText;

parameters[1].Value = ID;
try

{

return RunProcedure("sp_SearchProdList", parameters, "ProductList");

}

catch (SqlException e)

{

throw new AppException("An error executing the
Product_GetProdList method", e );

}

}

}




Aug 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
2
by: Martin Raychev | last post by:
Hi all, I have the following problem: I have a private method that returns a SqlDataReader. For this to work I have not to close the DB connection in the above method. I do this only to
2
by: Grant | last post by:
Hi, I keep getting the following error message: InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first. I have read up...
15
by: Rob Nicholson | last post by:
I'm starting to worry a bit now. We're getting the above error when two users hit the same database/page on an ASP.NET application using ADO.NET, talking to a SQL 7 server. The error is perfectly...
3
by: Rykie | last post by:
I have an application that constantly needs to read and write data to a SQL box. For most of my read transactions I use a datareader. I compiled a class that has all my datareader commands in it...
8
by: Stephen Costanzo | last post by:
We have an application that uses a SQLDataReader to cycle through a control table in the database and process records based upon that data. These records include things like the directory to poll...
2
by: rn5a | last post by:
The following code resides in a VB class file name GetOrder.vb (this class file exists in the App_Code directory): Namespace Shop Public Class Orders Public Function ViewOrder(ByVal UserID As...
3
by: BLUE | last post by:
I've a TransactionScope in which I select some data and I want to do some queries for each record retrieved with my select. I'm using a DataReader and for each record I do factory.CreateCommand()...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.