Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,


How to connect sqlServer in asp.net through webconfig?
Posted

In your web.config, add a connection string entry:

<connectionstrings><br />
  <add><br />
    name="LocalSqlServer" <br />
    connectionString="Data Source=amit\sqlexpress;Initial <br />
    Catalog=MyDatabase;User ID=userName;Password=password"<br />
    providerName="System.Data.SqlClient"<br />
  /><br />
</add></connectionstrings>


and then on
.cs Page U can get connection by Using

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
 
Share this answer
 
v2
You can get Connection String from visual studio itself by following some simple steps
Get SQL Server Database Connection String Easily from Visual Studio[^]

and copy connection string and put it in web.config.

Some of ways to set connection string you find from
http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config[^]
 
Share this answer
 
XML
<connectionStrings>
    <add providerName="System.Data.SqlClient" connectionString="Data Source=RIYAAZ-PC\SQLEXPRESS;Initial Catalog=UPDATED_OT;Integrated Security=True" name="WINDOW_APPLICATION"/>
  </connectionStrings>


.cs file:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["WINDOW_APPLICATION"].ConnectionString);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900