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.


  Modified On Sep-18-2014 01:23:55 PM
  1. create an app.config file (Add----> New Item-----> Application configuration file)

    you will get this:

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

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

    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