Link to home
Start Free TrialLog in
Avatar of David Bach
David BachFlag for United States of America

asked on

How To Connect To A Database In Application_Start Of Global.asax

Greetings;

I understand there is a way to connect to a SQL database within the Application_Start section of the Global.asax file, however, I have not found a good example of this. I am looking for a sample connect and subsequent reference to the connect object name from VB page behind.

Please let me know if I'm on the wrong track in my thinking or if this is a commonly done coding practice and an example of how to do it showing the Global.asax code and a sample snippet of VB code in the code-behind for a page.


Much thanks ... David
Avatar of greenguy
greenguy

I'd be happy to answer your question - but first I wanted to clarify what you are trying to accomplish -

Do you need to load values from the database at Application_Start?
Are you just looking for a way to write code that you can reuse throughout your application?
SOLUTION
Avatar of s_sansanwal
s_sansanwal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Bach

ASKER

Thank you greenguy and sansanwal.

To answer greenguy's question -- I am looking for a method to connect to the database one time when the application is opened and re-use the connection throughout the life of the application (which I understand ends when the web server is brought down or re-cycled). The solution I'm looking for is to minimize the number of times connections are created, opened, closed then disposed of on the basis the less this occurs the better performance will be.

To comment on sansanwal comment -- when you mention "data layer" I do have separate projects within the solution (Visual Studio .NET) which are classes (as opposed to web applications) that I interact with from the web application to facilitate connecting to the database, issuing a command object and loading a dataset. The dataset object I define in the web application, then pass reference to the dataset to the class, fill the dataset within the class and return control back to the web application which can then utilize the filled dataset. Is this what you mean by handling database functions in the data layer?

Much thanks ... David
SOLUTION
Avatar of Swapnil
Swapnil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial