Database Connection String

minn

Active member
Joined
Apr 10, 2006
Messages
37
Programming Experience
Beginner
Hello,

I have around 10 webforms that all use the same connection string. In the code-behind of each web-form i declare and define this connection string.

Rather than do it 10+ times, how do i define the connection string once, and have all may webforms refer to this?

Help much appreciated!
 
define your connection string in web.config file then create a class to access that string.. i think this will help a lot.. even when you have to change your connection. you have change it only at one place
 
Thanks!

I however have done it an alternative way. I created a class that defines the connection string and then a property that gets the connection string.

The rest of my forms that reference the property of this class.
This works but is the webconfig method a better way of doing it?
 
Hi,

Web Config is better because if you need to change the connection string, you can just change it in the web config. After changing, there is no need for re-building of the solution.

If you define a class, you have to re-build in order to make the change.
 
Back
Top