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