473,407 Members | 2,326 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,407 software developers and data experts.

Database Connection Management

OL
Hello All,

I need help understanding DB connection mgmt.

Scenario:

- 3 separate Web application
- IIS 5 or 6
- dynamic pages for most part
- DB Backend is Adaptive server Anywhere from sybase (max 10 concurrent
connections)
- Single machine: win 2k server + IIS + DB engine (80GB HDD, P4 2.8GHz, 1GB
RAM)

10-11k users /day (each downloads as many as 10 - 12 dynamic pages/forms)

Using ODBC for DB connections (and queries, updates, deletes etc...).
This functionality is in a dll which I initialize in "global.asax"
"App_start" event, for each web application.

The webforms call functions in this dll. Queries are returned in a
datastore. Actions (updates, deletes etc...) return success/fail code.

1. I am concerned about deadlocks
2. would like to limit:
web app 1 to max 5 concurrent connection
web app 2 to max 3 concurrent connection
web app 3 to max 1 connection

leaving 1 connection for admin purpose.
not sure if this matters but the calls inside the dll are like so:
Queries
1. getDS(ByVal selectStr As String, ByRef ds As DataSet) As DataSet
getDS calls DoAdapterCreate(selectStr, objDA, cn)
objDA.Fill(ds)
Me.DoAdapterDestroy(objDA, cn)
return DS

2. DoAdapterCreate(selectStr, objDA, cn)
DoAdapterCreate calls:
doConnect(cn) - which returns a connected ODBC Connection to
DoAdapterCreate
DoAdapterCreate returns objDA (an OdbcDataAdapter)

3. Me.DoAdapterDestroy(objDA, cn)
objDA.Dispose()
objDA = Nothing
DoDisConnect(cn) closes CN and dispose of connection object

Do I need to set a Application("_connectionCount") variable? and make sure
count is not > then x (where x is number of allowed connections)

NonQueries
Operate in simmilar fashion call mades from webforms to dll

TIA

OL
Nov 18 '05 #1
3 1970
Hi OL:

I'm afraid I do not know anything about Adaptive Server, but a couple
things came to mind about your post.

Some data providers allow you to specify the max # of connections to
use in the connection string, you might want to check the Sybase docs
to see if they do this.

If not, you could use a synchronization object known as a semaphore. A
semaphore allows from 1 .. n threads access to a protected resource,
for your scenario you could set n at 3 or 5 depending on the web app.
Unfortuantely there is no semaphore class provided by .NET in 1.x, but
there are semaphore functions you can PInvoke in Win32. See for
instance: http://pinvoke.net/default.aspx/kern...reateSemaphore

Also, make certain you are closing your connection as soon as
possible. You probably want to put your code inside a try / catch /
finally block to ensure DoDisConnect happens 100% of the time - even
if something else blows up with an exception.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 14 Nov 2004 10:35:08 -0500, "OL" <no****@verizon.net> wrote:
Hello All,

I need help understanding DB connection mgmt.

Scenario:

- 3 separate Web application
- IIS 5 or 6
- dynamic pages for most part
- DB Backend is Adaptive server Anywhere from sybase (max 10 concurrent
connections)
- Single machine: win 2k server + IIS + DB engine (80GB HDD, P4 2.8GHz, 1GB
RAM)

10-11k users /day (each downloads as many as 10 - 12 dynamic pages/forms)

Using ODBC for DB connections (and queries, updates, deletes etc...).
This functionality is in a dll which I initialize in "global.asax"
"App_start" event, for each web application.

The webforms call functions in this dll. Queries are returned in a
datastore. Actions (updates, deletes etc...) return success/fail code.

1. I am concerned about deadlocks
2. would like to limit:
web app 1 to max 5 concurrent connection
web app 2 to max 3 concurrent connection
web app 3 to max 1 connection

leaving 1 connection for admin purpose.
not sure if this matters but the calls inside the dll are like so:
Queries
1. getDS(ByVal selectStr As String, ByRef ds As DataSet) As DataSet
getDS calls DoAdapterCreate(selectStr, objDA, cn)
objDA.Fill(ds)
Me.DoAdapterDestroy(objDA, cn)
return DS

2. DoAdapterCreate(selectStr, objDA, cn)
DoAdapterCreate calls:
doConnect(cn) - which returns a connected ODBC Connection to
DoAdapterCreate
DoAdapterCreate returns objDA (an OdbcDataAdapter)

3. Me.DoAdapterDestroy(objDA, cn)
objDA.Dispose()
objDA = Nothing
DoDisConnect(cn) closes CN and dispose of connection object

Do I need to set a Application("_connectionCount") variable? and make sure
count is not > then x (where x is number of allowed connections)

NonQueries
Operate in simmilar fashion call mades from webforms to dll

TIA

OL


Nov 18 '05 #2
OL
Hello Scott,

Thank you for responding to my post.

First thanx for the "try / catch / finally" reminder, I will correct the
code as it requires correcting...

Now as to managing the connections.
From your reply I understand that I still MUST manage the connections usage
my self.

What I am not clear about is the general idea on how it's done.
Do I do "CreateSemaphore" and let it manage the connections?
Do I create an application var for "used connection count" and then from
each session do
a app.lock/update count/app.unlock (then use connection if available or wait
for connection if not available )?

I guess I can serialize nonQuery action to prevent deadlocks (1 connection)
and use the other connections for Queries.

I guess what I'm missing is the general concept of where to put which code,
what does dotnet manage for me (connection pool) etc. Is there an article or
KB out there , that you know of, that I can read

thanks again,

OL

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:m9********************************@4ax.com...
Hi OL:

I'm afraid I do not know anything about Adaptive Server, but a couple
things came to mind about your post.

Some data providers allow you to specify the max # of connections to
use in the connection string, you might want to check the Sybase docs
to see if they do this.

If not, you could use a synchronization object known as a semaphore. A
semaphore allows from 1 .. n threads access to a protected resource,
for your scenario you could set n at 3 or 5 depending on the web app.
Unfortuantely there is no semaphore class provided by .NET in 1.x, but
there are semaphore functions you can PInvoke in Win32. See for
instance: http://pinvoke.net/default.aspx/kern...reateSemaphore

Also, make certain you are closing your connection as soon as
possible. You probably want to put your code inside a try / catch /
finally block to ensure DoDisConnect happens 100% of the time - even
if something else blows up with an exception.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 14 Nov 2004 10:35:08 -0500, "OL" <no****@verizon.net> wrote:
Hello All,

I need help understanding DB connection mgmt.

Scenario:

- 3 separate Web application
- IIS 5 or 6
- dynamic pages for most part
- DB Backend is Adaptive server Anywhere from sybase (max 10 concurrent
connections)
- Single machine: win 2k server + IIS + DB engine (80GB HDD, P4 2.8GHz,
1GB
RAM)

10-11k users /day (each downloads as many as 10 - 12 dynamic pages/forms)

Using ODBC for DB connections (and queries, updates, deletes etc...).
This functionality is in a dll which I initialize in "global.asax"
"App_start" event, for each web application.

The webforms call functions in this dll. Queries are returned in a
datastore. Actions (updates, deletes etc...) return success/fail code.

1. I am concerned about deadlocks
2. would like to limit:
web app 1 to max 5 concurrent connection
web app 2 to max 3 concurrent connection
web app 3 to max 1 connection

leaving 1 connection for admin purpose.
not sure if this matters but the calls inside the dll are like so:
Queries
1. getDS(ByVal selectStr As String, ByRef ds As DataSet) As DataSet
getDS calls DoAdapterCreate(selectStr, objDA, cn)
objDA.Fill(ds)
Me.DoAdapterDestroy(objDA, cn)
return DS

2. DoAdapterCreate(selectStr, objDA, cn)
DoAdapterCreate calls:
doConnect(cn) - which returns a connected ODBC Connection to
DoAdapterCreate
DoAdapterCreate returns objDA (an OdbcDataAdapter)

3. Me.DoAdapterDestroy(objDA, cn)
objDA.Dispose()
objDA = Nothing
DoDisConnect(cn) closes CN and dispose of connection object

Do I need to set a Application("_connectionCount") variable? and make
sure
count is not > then x (where x is number of allowed connections)

NonQueries
Operate in simmilar fashion call mades from webforms to dll

TIA

OL


Nov 18 '05 #3
Hi OL:

You might want to check with Sybase first to see what their
documentation has. Some of these companies oferring thier own ADO.NET
data providers have some pretty quirky functionality.

Keeping track of the number of connections used would involve a
counter and a lock, this is essentially what a semaphore does.
Hopefully Sybase can provide this for you, but if not you'll need to
implement something inside of the methods where you connect and create
the datasets. Locking is dangerous in a web app if you don't have
experience writing that kind of code, hopefully you can avoid it.

This document is not specific to Sybase but it has a plethora of good
information and links:

..NET Data Access Architecture Guide
http://msdn.microsoft.com/library/de.../html/daag.asp

Particularly the sections "Managing database connections" and "
Error handling".

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 15 Nov 2004 11:14:00 -0500, "OL" <no****@verizon.net> wrote:
Hello Scott,

Thank you for responding to my post.

First thanx for the "try / catch / finally" reminder, I will correct the
code as it requires correcting...

Now as to managing the connections.
From your reply I understand that I still MUST manage the connections usage
my self.

What I am not clear about is the general idea on how it's done.
Do I do "CreateSemaphore" and let it manage the connections?
Do I create an application var for "used connection count" and then from
each session do
a app.lock/update count/app.unlock (then use connection if available or wait
for connection if not available )?

I guess I can serialize nonQuery action to prevent deadlocks (1 connection)
and use the other connections for Queries.

I guess what I'm missing is the general concept of where to put which code,
what does dotnet manage for me (connection pool) etc. Is there an article or
KB out there , that you know of, that I can read

thanks again,

OL

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:m9********************************@4ax.com.. .
Hi OL:

I'm afraid I do not know anything about Adaptive Server, but a couple
things came to mind about your post.

Some data providers allow you to specify the max # of connections to
use in the connection string, you might want to check the Sybase docs
to see if they do this.

If not, you could use a synchronization object known as a semaphore. A
semaphore allows from 1 .. n threads access to a protected resource,
for your scenario you could set n at 3 or 5 depending on the web app.
Unfortuantely there is no semaphore class provided by .NET in 1.x, but
there are semaphore functions you can PInvoke in Win32. See for
instance: http://pinvoke.net/default.aspx/kern...reateSemaphore

Also, make certain you are closing your connection as soon as
possible. You probably want to put your code inside a try / catch /
finally block to ensure DoDisConnect happens 100% of the time - even
if something else blows up with an exception.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 14 Nov 2004 10:35:08 -0500, "OL" <no****@verizon.net> wrote:
Hello All,

I need help understanding DB connection mgmt.

Scenario:

- 3 separate Web application
- IIS 5 or 6
- dynamic pages for most part
- DB Backend is Adaptive server Anywhere from sybase (max 10 concurrent
connections)
- Single machine: win 2k server + IIS + DB engine (80GB HDD, P4 2.8GHz,
1GB
RAM)

10-11k users /day (each downloads as many as 10 - 12 dynamic pages/forms)

Using ODBC for DB connections (and queries, updates, deletes etc...).
This functionality is in a dll which I initialize in "global.asax"
"App_start" event, for each web application.

The webforms call functions in this dll. Queries are returned in a
datastore. Actions (updates, deletes etc...) return success/fail code.

1. I am concerned about deadlocks
2. would like to limit:
web app 1 to max 5 concurrent connection
web app 2 to max 3 concurrent connection
web app 3 to max 1 connection

leaving 1 connection for admin purpose.
not sure if this matters but the calls inside the dll are like so:
Queries
1. getDS(ByVal selectStr As String, ByRef ds As DataSet) As DataSet
getDS calls DoAdapterCreate(selectStr, objDA, cn)
objDA.Fill(ds)
Me.DoAdapterDestroy(objDA, cn)
return DS

2. DoAdapterCreate(selectStr, objDA, cn)
DoAdapterCreate calls:
doConnect(cn) - which returns a connected ODBC Connection to
DoAdapterCreate
DoAdapterCreate returns objDA (an OdbcDataAdapter)

3. Me.DoAdapterDestroy(objDA, cn)
objDA.Dispose()
objDA = Nothing
DoDisConnect(cn) closes CN and dispose of connection object

Do I need to set a Application("_connectionCount") variable? and make
sure
count is not > then x (where x is number of allowed connections)

NonQueries
Operate in simmilar fashion call mades from webforms to dll

TIA

OL



Nov 18 '05 #4

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

Similar topics

4
by: Matt Young | last post by:
I've been tasked with integrating an older management system based on DBF files with my snappy new ASP application to provide users of the ASP application with real-time data from the management...
1
by: Ryan | last post by:
Is there an accepted strategy/design for database password management? Multiple asp.net web applications all talking to the same database. Each web app is on a separate machine and connectivity...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
3
by: Freddie | last post by:
hi, i try to get the asp.net 2.0 security controls to work with SQL Server 2005 Dev RTM, this is my connetion string in mashine.config <connectionStrings> <add name="LocalSqlServer"...
0
by: Jonathan Wood | last post by:
I seem to be having errors creating and accessing an SQL database. Unfortunatley, I am brand new to SQL setup and administration issues so this really is not my area of expertise. I know I had...
5
by: John | last post by:
I have an ASP.NET 2.0 application developed in VB.net, that accesses an Microsoft Access database. When the database is on the same IIS server all works just fine. BUT when it tried to access the...
4
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
This is kind of a cross forum problem. I am trying to Connect to database by clicking on: Tools Connect To Database Select: Microsoft SQL Server (SqlClient). However, there are no server listed...
3
eboschi
by: eboschi | last post by:
Hi all, i'm new to .net programming and i have some problems with database connection. I have written two web application. Both of them use ADODB Connection to Sql Server 2000 database. The problem...
3
by: =?Utf-8?B?Sm9obkJhdGVz?= | last post by:
I'm trying to (programatically) backup and clear the security event log on the local machine. I can do this manually through the event viewer and I am logged on as an administrator. I can...
1
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
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
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
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.