by Jim Rhoades (2 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 12th September 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
DSN-less logon to a SQL Server database
'Purpose: Logon to SQL Server....
Dim CN1 As New ADODB.Connection
Dim sAdoConStr As String
On Error GoTo LogonError
sAdoConStr = "UID=SA" & _
";PWD=" & _
";Server=Server123" & _
";Database=MyDataBase" & _
";App=My Application Name"
With CN1 ' Establish DSN-less connection
.ConnectionString = sAdoConStr
.ConnectionTimeout = 60
.CommandTimeout = 60
.CursorLocation = adUseClient
.Provider = "SQLOLEDB"
.Open
End With
GoTo LogonExit
LogonError:
MsgBox "Please contact your Network or Database Administrator." & _
"Inform them that you are unable to connect to the Server." & _
vbCrLf & "The following Error number was generated: " & Err.Number & _
vbCrLf & Err.Description, vbOKOnly + vbInformation, "LOGON ERROR"
End
LogonExit:
End Sub