Globalized connection string meant for that if you are designing a vast application that having so many windows forms and you need to control all the application using an app.config file.

 

  1. create an app.config file (Add----> New Item-----> Application configuration file)

    you will get this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>

        <add key="GlobalConnectionName" value="Data Source = serverAddress;Initial Catalog = DBName;User Id=xyz;    Password=xxxx;"/>
       
      </appSettings>
    </configuration>

    Now where you want to use this GlobalConnection :
    Add "System.Configuration" Namespace

    create your connection object:
    SqlConnection con=new SqlConnection();

     con.ConnectionString = ConfigurationSettings.AppSettings["GlobalConnectionName"];



    & you are done......

Leave Comment