Microsoft SQL database connection strings

With DSN

<% dbconn=”Provider=SQLOLEDB.1;UID=user;Password=password;Initial Catalog=DSNname;Data Source=IPaddressoftheSQLserver,PortNumber” %>

OLE DB

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

With DSN

<%
Set Conn = Server.CreateObject(“ADODB.Connection”)
Conn.open “DSN=DSNname;UID=user;PWD=password;DATABASE=mydatabasename”
%>

Without DSN

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

NOTE: If you do not want to put your SQL 2000 connection string on your actual ASP pages where the public can view the source and see it, you can create an include file from a hidden page and then call it from within your page where desired. This is a common practice and often used to protect your SQL database.

Leave a Reply