Browse Search  
Home :ASP :

How to connect to MSSQL from ASP Coding
Category : ASP
 
 

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;

 
 
This article has been viewed 122 times.



ASPWebHosting.com.au Copyright © 2004-2005 | All Rights Reserved |

All trademarks are property of their legal owners.