none
How can I read the ConnectionString from app.Config RRS feed

  • Question

  • Hi,

    in VB .NET 2003 i can read the connection string from the app.Config file as following:



    Dim AppSettingsReader1 As System.Configuration.AppSettingsReader
    Dim s As String = CType(AppSettingsReader1.GetValue("ConnectionString", GetType(System.String)), String)


     



    in app.Config file you can find the setting like this:



    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
     <appSettings>
      <!--   User application and configured property settings go here.-->
      <!--   Example: <add key="settingName" value="settingValue"/> -->
        <add key="SqlConnection1.ConnectionString" value="workstation id=HPHOME;packet size=4096;integrated security=SSPI;data source=HPHOME;persist security info=False;initial catalog=AlWaqf" />
      <add key="ConnectionString" value="workstation id=SQLSERVER;packet size=4096;integrated security=SSPI;data source=SQLSERVER;persist security info=False;initial catalog=MYDB" />
     </appSettings>
    </configuration>

     


    The setting in app.Config 2005 file is changed to:



    <connectionStrings>

    <add name="Waqf.Settings.ConnectionString" connectionString="Data Source=SQLSERVER;Initial Catalog=MYDB;Integrated Security=True"

    providerName="System.Data.SqlClient" />

    </connectionStrings>


     



    SO, there is not Value in the new setting file and GetValue does not work here.

    How can I read the connection string from app.Config file?

    Thanks alot

    Wednesday, November 2, 2005 6:53 PM

Answers

  • Oh, I found it.

    It is simplest than VB .NET 2003.

    All what you need to do is to use the new MY.Setting.ConnectionString to get the connectionString the you had stored in app.Config file

    Thanks for me Smile
    Wednesday, November 2, 2005 8:05 PM