What is MSSQL DB Connection String?

MSSQL DB connection string is used in ASP/.NET pages to retrieve data from the MSSQL databases. This article guides you to create your connection string.

This is a sample connection string which you can use with MSSQL 2008/2012, ASP.NET 3.5 and above versions.

The following connection string has to be created in web.config file

<connectionStrings>

<add name="ConnectionString" connectionString="Data Source=(server IP)\(database instance);Initial Catalog=(database name);User ID=(database username);Password=(database password)" providerName="System.Data.SqlClient" />

</connectionStrings>

Following properties have to be changed in connection string;

  1. Data Source : This should be the server name of MSSQL or server IP address like "localhost" or "X.X.X.X".
  2. Initial Catalog: Full name of the database that you have created (you can find it in Plesk panel)
  3. User Id : The username that you have created in your Plesk panel to access the DB (Please make sure the access has been granted for this user to access the DB)
  4. Password: Password of the MSSQL DB user created in Plesk panel.\

You can use ConfigurationSettings class to read the connection string in your code

string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

Note: You cannot the same connectionString on your local PC to connect MSSQL DB server. It won't work as the server side configurations are different and we do not allow remote access to the hosted databases.

Another option is to use the following string as the connection string

Data Source=localhost;Initial Catalog=Your_Database;Persist Security Info=True;User ID=Database_Username;Password=Database_Password

The "Data Source=" depends on the database version you chose for the database in Plesk panel. You may need to use .\MSSQLSERVER2008 or .\MSSQLSERVER2012 instead.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How do I access my control panel?

Please use https://www.yourdomain.com:8443/ instead of "www.yourdomain.com". Please...

How do I change file permissions in Plesk?

Customers have total control of their site for permissions i.e. installing 3rd party scripts if...

My website is showing a "500 Internal Server Error! What is this?"

If you are getting a 500 Internal Server Error, it means that there is a problem with the...

SSL Certificate warning on Plesk login page

Upon initial access to Plesk control panel via HTTPS (eg. https://1.1.1.1:8443), your web browser...

Web Publishing with Web Deploy via Visual Studio

Our Plesk shared hosting supports Web Deploy publishing. It allows you to use Visual Studio to...