Tuesday, July 28, 2009

CONNECTION STRING IN WEB.CONFIG IN C#

Dear Fellows,

You can create declare connection string in web.config file. You can do so by

<add name="Connection_Name" connectionString="server=(local);database=database_name;uid=sa;pwd=sa" providerName="System.Data.SqlClient"/>

Now you can call this connection in any .aspx page by this command.

NOTE: I am getting connection string in a string variable named "Path"

string path = System.Configuration.ConfigurationManager.ConnectionStrings["Connection_Name"].ConnectionString;

See how simple is this. In the same way you can use this connection string in all your .aspx pages.

Take Care and Enjoy...............

No comments: