How to connect to MSSQL from ASP Coding?

Before you can access your MS-SQL Server database from your ASP code , you need to connect to it using one of the following available methods:

1. Connect to a MS-SQL database with OLEDB:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=SQLOLEDB; Data Source=(serverIP); Initial
Catalog=your_database_name; User ID=your_username; Password=your_password"
objConn.Close
Set objConn = Nothing

2. Connect to a MS-SQL Server database with MS-SQL Driver:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Driver={SQL Server};" & _
"Server=(serverIP);" & _
"Database=your_database_name;" & _
"Uid=your_username;" & _
"Pwd=your_password;"
objConn.Close
Set objConn = Nothing

PS: change the (serverIP) to match your conn string

for example if you mssql hostname is:   127.0.0.1,123

then you have to change the string from
Server=(serverIP);

to

Server=127.0.0.1,123;

Was this answer helpful?

 Print this Article

Also Read

What ASP components do you have installed?

We have ASPMail, ASPUpload, ASPimage, SA File-Up, Jmail, ASP Postit and ASPHttp, ASP TreeView,...

I get an error 'Server.CreateObject Failed' when I try to use CDONTs. What can I do?

...

How do I send email from ASP using SMTP Authentication?

Please note that our mail server is configured with Authentication. Below is the code snippet...

How do I set multiple domain or subdomain without using my website limits?

For multiple domain to work correctly, you have to set domain pointer for your site.For.eg, you...

I got 500 Error when viewing my Site ? Please help !!!

This normally happens because you turn on the Friendly Error on your IE. By default, IE always...