asp.net connection string?

hai all,

I had one doubt in asp.net connection string.

I can write the connection string in web.config file.

I could open connection from each page.

Is it the only way to open connection is through each page or any

other method is there.

Any one please guide me

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Tags:

This entry was posted on Monday, May 31st, 2010 at 8:14 am and is filed under Connection string. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

3 Responses to “asp.net connection string?”

  1. Kevin Says:

    you can probably open it once and then store it as a session variable and keep using it over and over.

  2. Kevin Says:

    The database connection string belongs in web.config
    Here are some videos on asp.net Click on all three tiers they advance your learning as you progress.
    http://msdn.microsoft.com/vstudio/express/beginner/web/tier1
    Try using Visual Web Developer Express, it is free and easy to use. Will handle the conneciton to the database “automatically” for you.
    SQL videos build a nice web site in ASP.NET 2.0. using Visual Web Developer and working with web.config and SQL Connections strings.
    The free SQL 2005 Express Edition and SQL Mangaer
    http://msdn.microsoft.com/vstudio/express/sql/
    Free videos on SQL, the best ever for free.
    http://msdn.microsoft.com/vstudio/express/sql/learning/default.aspx

  3. Kevin Says:

    Yes, the best way is to store the connection string in your web.config file.

    Then whenever you need to instantiate a Connection Object, you can read the connection string from your config file.

    The advantage here is that you have the connection string in a centralised place. Whenever the application is moved from a server to another, you do not have to recompile your application. You merely adjust your web.config file.

    Storing the connection object in a session variable as mentioned above is a terrible idea!! The pattern that should be followed whenever you need to access your data tier is as follows:

    1- instantiate a connection object (reading the connection string from your config file)
    2- Open the connection
    3- Execute your Queries
    4- Close the connection
    5- Dispose the connection.

    Hope this helps.

Leave a Reply

 

About - Contact - Privacy Policy - Terms of Service