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;

  • 15 Пользователи нашли это полезным
Помог ли вам данный ответ?

Связанные статьи

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?

CDONTs is no longer supported on Windows 2003 server.  Microsoft introduced CDO back several...

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

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