473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Data Access Architecture Advice

I need advice on correct usage of ADO.NET in an ASP.Net environment.
I have an ASP.Net application that accesses data through a referenced
class library. Things start to break down when multiple web clients
attempt to use the application at the same time. A common error that
gets returned is "sqlcommand is currently busy open, fetching".
I can't understand why the users might be using the same instance of
my connection, but this error message would seem to indicate that they
are.

Below is an outline of my applications architecture.
I would appreciate any advice or suggestions as to what I might change
in my approach to get my ASP.Net application connecting to data in a
multiuser environment.

Classes that contains my business logic:

Public Class AAA
Private CON As New SqlClient.SqlConnection()
Private RDR As SqlClient.SqlDataReader
Private CMD As New SqlClient.SqlCommand()

Public Sub DoStuff
Common.ConnectDatabase(CON, "Staff")
CMD.CommandText = "SELECT * FROM tblStaff"
CMD.Connection = CON
RDR = CMD.ExecuteReader
If RDR.Read = False Then
....
....
End If
RDR.Close()
CON.Close()
End Sub
End Class

This module lives in the same dll as my business logic and contains
commonly used stuff like connecting to databases:

Public Module Common
Public Function ConnectDatabase(ByRef CON As SqlClient.SqlConnection,
ByVal sDatabase As String) As Boolean
Try
Select Case sDatabase
Case "Staff"
CON = New System.Data.SqlClient.SqlConnection()
CON.ConnectionString = "Integrated
Security=False;User ID=;Password=;Initial Catalog=Staff;Data
Source=myserver;"
CON.Open()
End Select
Catch
Return False
End Try
Return True
End Function
End Class

Now, my ASP.Net web pages interact with the above code like this:
(Note - all my code is in code behind. This is an example from an
aspx
page called Staff.aspx)

Public Class Staff
Protected MyClass as New AAA()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PrintStaff()
End Sub

Private Sub PrintStaff()
MyClass.DoStuff
End Sub
End Class

The philosophy is that everytime a method in my classes is called a
connection is opened, actions are performed, then the connection is
closed. Note that I do not "dispose" of the collection so it should
be returned to the pool. One of the things I am trying to achieve by
following this approach is to take any concern for attaching to
databases away from the coder building the ASP.Net pages. The classes
perform all data activity.
Nov 17 '05 #1
4 1379
At what line does it generate that error? I've gotten that before but don't
remember what the problem was..

"Heath Kelly" <so******@NOSPAM.diskcovery.com.au> wrote in message
news:eB**************@tk2msftngp13.phx.gbl...
I need advice on correct usage of ADO.NET in an ASP.Net environment.
I have an ASP.Net application that accesses data through a referenced
class library. Things start to break down when multiple web clients
attempt to use the application at the same time. A common error that
gets returned is "sqlcommand is currently busy open, fetching".
I can't understand why the users might be using the same instance of
my connection, but this error message would seem to indicate that they
are.

Below is an outline of my applications architecture.
I would appreciate any advice or suggestions as to what I might change
in my approach to get my ASP.Net application connecting to data in a
multiuser environment.

Classes that contains my business logic:

Public Class AAA
Private CON As New SqlClient.SqlConnection()
Private RDR As SqlClient.SqlDataReader
Private CMD As New SqlClient.SqlCommand()

Public Sub DoStuff
Common.ConnectDatabase(CON, "Staff")
CMD.CommandText = "SELECT * FROM tblStaff"
CMD.Connection = CON
RDR = CMD.ExecuteReader
If RDR.Read = False Then
...
...
End If
RDR.Close()
CON.Close()
End Sub
End Class

This module lives in the same dll as my business logic and contains
commonly used stuff like connecting to databases:

Public Module Common
Public Function ConnectDatabase(ByRef CON As SqlClient.SqlConnection,
ByVal sDatabase As String) As Boolean
Try
Select Case sDatabase
Case "Staff"
CON = New System.Data.SqlClient.SqlConnection()
CON.ConnectionString = "Integrated
Security=False;User ID=;Password=;Initial Catalog=Staff;Data
Source=myserver;"
CON.Open()
End Select
Catch
Return False
End Try
Return True
End Function
End Class

Now, my ASP.Net web pages interact with the above code like this:
(Note - all my code is in code behind. This is an example from an
aspx
page called Staff.aspx)

Public Class Staff
Protected MyClass as New AAA()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PrintStaff()
End Sub

Private Sub PrintStaff()
MyClass.DoStuff
End Sub
End Class

The philosophy is that everytime a method in my classes is called a
connection is opened, actions are performed, then the connection is
closed. Note that I do not "dispose" of the collection so it should
be returned to the pool. One of the things I am trying to achieve by
following this approach is to take any concern for attaching to
databases away from the coder building the ASP.Net pages. The classes
perform all data activity.

Nov 17 '05 #2
How big is your table tblStaff? Do you have where clause and indexes with
it?

"Heath Kelly" <so******@NOSPAM.diskcovery.com.au> wrote in message
news:eB**************@tk2msftngp13.phx.gbl...
I need advice on correct usage of ADO.NET in an ASP.Net environment.
I have an ASP.Net application that accesses data through a referenced
class library. Things start to break down when multiple web clients
attempt to use the application at the same time. A common error that
gets returned is "sqlcommand is currently busy open, fetching".
I can't understand why the users might be using the same instance of
my connection, but this error message would seem to indicate that they
are.

Below is an outline of my applications architecture.
I would appreciate any advice or suggestions as to what I might change
in my approach to get my ASP.Net application connecting to data in a
multiuser environment.

Classes that contains my business logic:

Public Class AAA
Private CON As New SqlClient.SqlConnection()
Private RDR As SqlClient.SqlDataReader
Private CMD As New SqlClient.SqlCommand()

Public Sub DoStuff
Common.ConnectDatabase(CON, "Staff")
CMD.CommandText = "SELECT * FROM tblStaff"
CMD.Connection = CON
RDR = CMD.ExecuteReader
If RDR.Read = False Then
...
...
End If
RDR.Close()
CON.Close()
End Sub
End Class

This module lives in the same dll as my business logic and contains
commonly used stuff like connecting to databases:

Public Module Common
Public Function ConnectDatabase(ByRef CON As SqlClient.SqlConnection,
ByVal sDatabase As String) As Boolean
Try
Select Case sDatabase
Case "Staff"
CON = New System.Data.SqlClient.SqlConnection()
CON.ConnectionString = "Integrated
Security=False;User ID=;Password=;Initial Catalog=Staff;Data
Source=myserver;"
CON.Open()
End Select
Catch
Return False
End Try
Return True
End Function
End Class

Now, my ASP.Net web pages interact with the above code like this:
(Note - all my code is in code behind. This is an example from an
aspx
page called Staff.aspx)

Public Class Staff
Protected MyClass as New AAA()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PrintStaff()
End Sub

Private Sub PrintStaff()
MyClass.DoStuff
End Sub
End Class

The philosophy is that everytime a method in my classes is called a
connection is opened, actions are performed, then the connection is
closed. Note that I do not "dispose" of the collection so it should
be returned to the pool. One of the things I am trying to achieve by
following this approach is to take any concern for attaching to
databases away from the coder building the ASP.Net pages. The classes
perform all data activity.

Nov 17 '05 #3
Hi Heath,

I think you may consider following things to reduce the conflicts:

1. Keep the connection open, don't close it on every request. The Open
command may comsume some time.
2. Use dataset and dataadapter instead of the datareader, If you only need
to retrieve data from database to your business layer, you can consider
dataadapter's Fill method.
3. If it is necessary, you can cache some statics records in Class AAA, for
example, in a dataset, so that you don't need to access database on
everytime.

Hope this help

Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."

Nov 17 '05 #4
The problem is that your class has a global Connection and Command. If you
try to execute certain database operations using the same instance of the
class, the different operations will be using the same Connection. This can
cause the type of problem you describe. Try removing the global variables,
and create Connection and Command variables inside the functions that use
them. Make sure the Connection is always closed by the function. Connection
Pooling will take care of the rest.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"Heath Kelly" <so******@NOSPAM.diskcovery.com.au> wrote in message
news:eB**************@tk2msftngp13.phx.gbl...
I need advice on correct usage of ADO.NET in an ASP.Net environment.
I have an ASP.Net application that accesses data through a referenced
class library. Things start to break down when multiple web clients
attempt to use the application at the same time. A common error that
gets returned is "sqlcommand is currently busy open, fetching".
I can't understand why the users might be using the same instance of
my connection, but this error message would seem to indicate that they
are.

Below is an outline of my applications architecture.
I would appreciate any advice or suggestions as to what I might change
in my approach to get my ASP.Net application connecting to data in a
multiuser environment.

Classes that contains my business logic:

Public Class AAA
Private CON As New SqlClient.SqlConnection()
Private RDR As SqlClient.SqlDataReader
Private CMD As New SqlClient.SqlCommand()

Public Sub DoStuff
Common.ConnectDatabase(CON, "Staff")
CMD.CommandText = "SELECT * FROM tblStaff"
CMD.Connection = CON
RDR = CMD.ExecuteReader
If RDR.Read = False Then
...
...
End If
RDR.Close()
CON.Close()
End Sub
End Class

This module lives in the same dll as my business logic and contains
commonly used stuff like connecting to databases:

Public Module Common
Public Function ConnectDatabase(ByRef CON As SqlClient.SqlConnection,
ByVal sDatabase As String) As Boolean
Try
Select Case sDatabase
Case "Staff"
CON = New System.Data.SqlClient.SqlConnection()
CON.ConnectionString = "Integrated
Security=False;User ID=;Password=;Initial Catalog=Staff;Data
Source=myserver;"
CON.Open()
End Select
Catch
Return False
End Try
Return True
End Function
End Class

Now, my ASP.Net web pages interact with the above code like this:
(Note - all my code is in code behind. This is an example from an
aspx
page called Staff.aspx)

Public Class Staff
Protected MyClass as New AAA()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PrintStaff()
End Sub

Private Sub PrintStaff()
MyClass.DoStuff
End Sub
End Class

The philosophy is that everytime a method in my classes is called a
connection is opened, actions are performed, then the connection is
closed. Note that I do not "dispose" of the collection so it should
be returned to the pool. One of the things I am trying to achieve by
following this approach is to take any concern for attaching to
databases away from the coder building the ASP.Net pages. The classes
perform all data activity.

Nov 17 '05 #5

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

Similar topics

1
by: Robert Zurer | last post by:
My architecture is, (ala Fowler PoEAA) Presentation Layer | Service Layer | Problem Domain (My Business Objects are held in memory) | Persistence Layer
26
by: Kip | last post by:
Greetings everyone, Is there anyone here who could point me to a page or pdf that has a list of the sizes of all of the C primitive data types on various implementations such as SPARC, x86,...
4
by: Oyvind | last post by:
I'm working on a Windows forms/C# database application. My background is 6-7 years of VB 4 - 6, MS Access, VC++, mixed in with a lot of T-SQL and MS SQL Server in general and some OOA/OOD. ...
1
by: Johann Blake | last post by:
I am looking for a good solution on how to implement data access in an application so that there is a clean separation between the data access layer, the business layer and the GUI layer. I am...
4
by: C Downey | last post by:
I am creating a data access layer and I'm interested in the best method of returning data to my business tier. My database is SQL Server 2000, and I use stored proc's. Is it better for me to use...
5
by: Natan | last post by:
I want to create an n-tier app and I would like an advice of you that know more than me about this. I want my app to support multiple databases in the way that when a client wants to use Oracle...
0
by: Prodip Saha | last post by:
http://www.aspnet4you.com/Articles.aspx?ArticleID=5017 Asynchronous Data Access in ASP.NET (Live demo) Author: Saha,Prodip Posted:5/15/2005 6:03:17 PM Web Architecture is becoming...
0
by: as_lev | last post by:
Hello! First, I want to reccomend the Fantasticthe article about distributed applications http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnbda/html/BOAGag.asp I am...
7
by: sathyashrayan | last post by:
Dear group, A mysql wrapper class, which just uses the CRUD operations for large scale php development. Is the same advisable for the mysql stored procedure? Following is a link I got from...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.