April 13, 2004
DSN-less Connections for SQL Server

I want to create a DNS-less connection to a SQL Server database.
How do I do it?

You can cut and paste the following snippet of code to build a suitable
DSN-less connection string for SQL Server.

Function strDBConnectString ( strServer, _
         strDatabase, strUser, strPass )

   Dim strResult
   strResult = "Provider=SQLOLEDB;" & _
               "Data Source=" & _
                    strServer & ";" & _
               "Initial Catalog=" & _
                    strDatabase & ";" & _
               "User ID=" & strUser & ";" & _
               "Password=" & strPass & ";"

   strDBConnectString = strResult				

End Function
Then, in your code, simply use the following:
'Create a Connection
Dim conn
conn = Server.CreateObject("ADODB.Connection")

' Build a connection string
' Use the appropriate Server Name, Database Name,
' User name and Password
Dim strConnString
strConnString = strDBConnectString ( "Svr", "DB", _ 
     "Usr", "Pass" )

' Now, connect...
conn.Open strConnString

Posted by WebWiz at April 13, 2004 01:59 PM

©2002-2004 zConnect
All Rights Reserved
admin
3600 Dallas Hwy STE 230 PMB288
Marietta, GA 30064-1685
support@zconn.net
770 590-0888
FAX 770 234-6721
Toll Free 1-800-959-8869