Posts
251
Comments
74
Trackbacks
4
Datenbank-Connection-String in Web.config speichern

Den Datenbank-Connection-String kann man in der Datei Web.Config zentral speichern und später an jeder Stelle des Programmes abrufen.

Eintrag in die Datei Web.Config (Beispiel mit einer Acces-DB):

<configuration>
    <appSettings>
   <add key="myConnection" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\datenbank.mdb;Persist Security Info=True" />
   </appSettings>
</configuration>

In der Anwendung kann der Connecion-String folgendermassen abgefragt werden (C#):

DBConnection = new OleDbConnection();
strConnect = System.Configuration.ConfigurationManager.AppSettings.Get("myConnection");
DBConnection.ConnectionString = strConnect;

 

posted on Monday, December 12, 2005 3:28 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 2 and 6 and type the answer here: