Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do you store your database connectionstring?

Tags:

asp.net

I usually store my connectionstring in web.config or in the application settings of my Visual Studio project. The application I'm currently working on makes a lot of trips to the database which means it will look up the connectionstring every time. Should I be putting the connectionstring in the cache or should I be looking at storing the whole SqlConnection object in the cache to eliminate the need to open and close them all the time?

Update: Seems like the consensus is to store the connection string in a configuration file and leave the caching in the trusting hand of ADO.NET

like image 641
Christian Hagelid Avatar asked Sep 03 '08 02:09

Christian Hagelid


1 Answers

I wouldn't cache the connection object, that will defeat the built-in connection pooling -- ADO.NET will handle connections (assuming you instantiate and close them) efficiently by itself.

As far as the connection string itself, you shouldn't need to cache it if you load it from connection -- the connection manager object in the .NET 2.0 framework loads the config into memory when you first access it, so there are no repeat trips to the file system.

like image 75
Guy Starbuck Avatar answered Sep 19 '22 01:09

Guy Starbuck