?
Solved

Multiple Database Connections vs Single Database Connection

Posted on 2004-04-30
9
Medium Priority
?
944 Views
Last Modified: 2007-12-19
Hi All,

I have an Oracle database which I want to connect to. I have an app running on my IIS server which the users will connect to.

The normal scenario is to when a request come to the web server it opens a connection to the database and then closes it when it is finished. This means for every client connection to the web server there is one to the server ... so if we have 1000 web connections we have 1000 database connections. This eats up too many resources.

I know that you can use some sort of session information to keep one database connection open and all the web requests use the same database connection.

I would like to get some information for it. And if anybody can give me a working ORACLE and C# example, you get the 500 points :)

Thanks
Peter
0
Comment
Question by:Pete2003
9 Comments
 
LVL 21

Accepted Solution

by:
tovvenki earned 2000 total points
ID: 10958044
Hi,

try this when you open the connection for the first time open it and save it in a session variable

OracleClient.OracleConnection conn = new OracleClient.OracleConnection ();
conn.ConnectionString = "Data Source=" + "<oracle data source name>;Integrated Security=yes";
    try
    {
        conn.Open();
        // Insert code to process data.
    }
        catch (Exception ex)
    {
        //("Failed to connect to data source");
    }

    Session["DbCon"] = conn;
-------------------------------------------------

now whereever you need to use the connection in the session use the following code

OracleClient.OracleConnection myconn  = (OracleClient.OracleConnection)Session["DbCon"];


hope that this helps you.

Regards,
venki

0
 

Author Comment

by:Pete2003
ID: 10958142
Thanks for the quick response ...

Ok maybe let me expand on what my problem a bit ...

If three users connect to the web server they each have a unique IIS connection session. I however want these separate application instances to use the SINGLE oracle connection.

I have seen this done ... ie: you have 10 people connected to the IIS server and using the database .. bu tthere is only one connection to the database server open.

0
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10958180
maybe you would have to store the database object in the application array not the session array
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 21

Expert Comment

by:tovvenki
ID: 10958225
then try with the Application object like

Application("DbCon") = conn;

myConn = (OracleClient.OracleConnection)Application["DbCon"];

0
 
LVL 6

Expert Comment

by:DaniPro
ID: 10958226
In Orcale .NET Provider there are connections pool for an ADO.NET application.
When you open a new connection, a connection pool's created with an alghoritm based on connection string; when you open a new connection, if the connection string is not the same of the previous connection, a new connection pool will be created.
A connection pool is delete when the active process end.
You don't need to store the connection in the session or application object, the connections pool are managed automatically from the server.

You can read this link for more detail:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconconnectionpoolingfornetdataproviderfororacle.asp
0
 

Author Comment

by:Pete2003
ID: 10958304
The application object does not work ...

OracleConnection conn = new OracleConnection ();
conn.ConnectionString = "User Id=user;Password=pass;Data Source=oradbase;Integrated Security=yes";
try
{
     conn.Open();
     Application("DbCon") = conn;
}
catch (Exception ex)
{
      //("Failed to connect to data source");
}

The error is

WebForm1.aspx.cs(25): 'System.Web.UI.Page.Application' denotes a 'property' where a 'method' was expected


shoudl I be including some extra library ?  it works with the session but not application ...


0
 

Author Comment

by:Pete2003
ID: 10958319
OOps sorry my mistake ( instead of [
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 10958342
hi,
it should be like
Application["DbCon"] = conn;
and not
Application("DbCon") = conn;

0
 

Author Comment

by:Pete2003
ID: 10958651
One final question ... the Application variable works in a web application ... how would this work if I wanted to put this into a library ?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question