What to use for MSSQL database connection string?



Please use following connection string syntax for connecting MSSQL DB from your ASP/.NET scripts.

 

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

You need to create below connection string in web.config file.


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



Important Properties to change in connection string.

 

1) Data Source : This should be your MSSQL server name or server IP address like "localhost" or "X.X.X.X".

2) Initial Catalog: You can find database full name in plesk panel where you orginally created the database.

3) User Id : Replace with user name you created on top of MSSQL DB in Plesk control panel.

4) password: Password of the MSSQL DB user created in Plesk control panel.

 

Once you created connectionString in web.config file, you can use it in your ASP pages to retrive the database.

 

======================
To read the connection string into your code, use the ConfigurationSettings class.

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

======================

 

Note: You can't use the same connectionString on your local PC to connect MSSQL DB server. It won't work as we don't allow remote connections to MSSQL server. It means you have to use/connect to MSSQL DB server through ASP/.NET scripts hosted on the same server.


Another option is to use the following string:

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

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

 

MSSQL SQL Connection string





Hai trovato questa risposta utile?

 Stampa Articolo

Leggi anche

Plesk says ASP.NET 4.0, but I need 4.5

It's because 4.5 is simply an update of 4.0, therefore in Plesk the version appears as 4.0...

How do I connect via RDP on my Windows VPS?

Windows Firewall is active by default, so RDP access will first need to allowed in the firewall...

DSNless connection string

DSNless connection string for use with .mdb MS Access, etc.: "DRIVER={Microsoft Access Driver...

Create SPF record in Plesk

Creating an SPF record can help with delivery sending issues and from other server rejecting your...

Multiple Windows hosting accounts and logging into Plesk

If you have multiple Windows hosting plans with us, when logging into Plesk, you need to login...