Einzelnen Beitrag anzeigen

Benutzerbild von Jelly
Jelly

Registriert seit: 11. Apr 2003
Ort: Moestroff (Luxemburg)
3.741 Beiträge
 
Delphi 2007 Professional
 
#1

ConnectionString aus Web.Config auslesen

  Alt 26. Apr 2007, 08:55
In der Hilfe hab ich folgenden Code gefunden, um aus der web.Config Datei eines ASP.NET Projektes einen connectionstring auszulesen:
Code:
        String str;
        System.Configuration.Configuration rootWebConfig =
             System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
        System.Configuration.ConnectionStringSettings connString;
        if (0 < rootWebConfig.ConnectionStrings.ConnectionStrings.Count)
        {
            connString =
                rootWebConfig.ConnectionStrings.ConnectionStrings[0];
            if (null != connString)
                str = connString.ConnectionString;
            else
                str = @"n/a";
            TextBox1.Text = rootWebConfig.FilePath + "   "+ str;
        }
Es steht in der Hilfer weiterhin:
Zitat von Online Hilfe:
To obtain configuration settings for the root-level Web configuration, null is passed to the OpenWebConfiguration method.
Das heisst für mich, es wird die web.config Datei geladen, die auch in meinem Webverzeichnis liegt.
Gebe ich mir aber den FilePath anschliessend an, so steht dadrin
Code:
rootWebConfig.FilePath = "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\web.config"
Warum das
  Mit Zitat antworten Zitat