Sample MSSQL Database Connection Strings

Database Management
These examples are for demonstration purposes only. You must paste this code in your ASP code to make a connection to the specified database. Note that you must change elements such as database name, server name, database location, dsn, and so on.

OLE DB

<%
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.open "PROVIDER=SQLOLEDB;DATA SOURCE=sqlservername;UID=username;PWD=password;DATABASE=mydatabase "
%>

With DSN

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=mydatabase"
%>

Without DSN

<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=mydatabase"
Conn.open DSNtest
%>

Add Feedback