Solved

Multiple Database Connections vs Single Database Connection

Posted on 2004-04-30
9
934 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 500 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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