Enter the following connection string in the web config as shown below
<connectionStrings>
<add name="SQLCON" connectionString="Data Source=OFFICE-PC\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=true;User id=sa;Password=;"/>
</connectionStrings>
Call the above in the aspx.cs page as shown below in the page load or as public
//Use this sql namespace at the starting along with the other namespaces as shown
Using System.Data.SqlClient
//Calling the Connectionstring
static string strcon = ConfigurationManager.ConnectionStrings["SQLCON"].ConnectionString;
//Create new sqlconnection and connection to database by using connection string from web.config file SqlConnection con = new SqlConnection(strcon);
No comments:
Post a Comment