ASP. net How to Connect to SQL SERVER 2012 Database

  • 2021-08-05 09:40:49
  • OfStack

Add in the web. config file


<connectionStrings>
<add name="SQLConnectionString" connectionString="Data Source= Server name ;Initial Catalog= Database name ;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Then add in the page where you need to connect to the database


// Get the database connection string 
public static string connString = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;

Related articles: