Knowledgebase: Windows Hosting
MSSQL DB Connection Strings with ASP/.NET
Posted by RAJU K, Last modified by Kim S. on 20 February 2016 07:27 PM

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.

        <connectionStrings>

<add name="myConnectionString" providerName="System.Data.SqlClient"  connectionString="Data Source=localhost;Initial Catalog=DB_Name;User Id =DB_user;password=DB_Pass;" />
 
</connectionStrings>
 

Important Properties to change in connection string:

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

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

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 data base.

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

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

---------

Note: You can't use 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 same server.


Comments (1)
Lingaraja Jena
13 October 2015 10:29 PM
Can you please provide MSSQL DB Connection Strings with CGI-PERL?
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).