Monday 24 May 2010

Connection String Settings in Web.config

1. Add following line to web.config file.

<connectionStrings>

<add name="Name" connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Persist Security Info=True;User ID=sa;Password=sa" providerName="System.Data.SqlClient"/>

connectionStrings>

Name = Provide any name of connection string.

Data Source = Server name. ex: SHUVRO\SQLEXPRESS

Initial Catalog = Database name. Ex: PCDB

2. Get the connection string from web.config file from cs

String ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["Name"].ConnectionString;

[“Name”] is the connection string name that is in web.config tag name

No comments:

Post a Comment