Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to configure database connection string in one place

Status
Not open for further replies.
Dec 29, 2001
73
GT
Hi fellows,

I'm starting to develop web based applications with ASP.NET, I have several pages and, as each page has it's own OleDbConnection control, the connection string is specified in every page.

I would like to allow the user to set the database connection string to use in a configuration page. I tried putting the connection string in a file and reading on application startup. It worked fairly well, however some databinding properties are no longer displayed correctly due to the connection string not being set in the object as string but as a function execution.

What is the best way to do what I want?

Thanks a lot,

Mauricio Peccorini
 
In the web.config file add
Code:
<appSettings>
		<add key = "DBConn" 
		value = "Provider = Microsoft.Jet.OLeDB.4.0; data source=C:\Inetpub\wwwroot\[appName]\[DatabaseName].mdb;"/>
</appSettings>
after the </system.web> tag.

Then all you have to do create the connection string anywhere in your app is:

Dim strConn As String = ConfigurationSettings.AppSettings("DbConn")
 
I have done that and it works pretty well in runtime. However, in design time it does not show the lists of allowed values in the databinding related properties.

Is there no other way?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top