Solved

Multiple Database Connections vs Single Database Connection

Posted on 2004-04-30
9
936 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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