How to configure Database Connection string in Web.Config for Asp.net 2.0?

How to configure Database Connection strings in Web.Config in Asp.net 2.0?



DB connection string configuration



<configuration>

<connectionStrings>

<add

name="myConnectionString"

connectionString="server=myServer\SQLEXPRESS;

initial catalog = myDataBase;

user id=myID;

password=myPassword"

/>



</connectionStrings>

</configuration>





Accessing Connection string from Web.config through coding in c#



SqlConnection con = new SqlConnection

(System.

Configuration.

ConfigurationManager.

ConnectionStrings["myConnectionString"].

ConnectionString)

No comments: