Function GetConnection(strDBName As String, Optional strUserName As String = "", Optional strPassword As String = "") As ADODB.Connection
On Error GoTo GetConnection_ErrHandler
Dim strConnectionString As String
strConnectionString = "Provider=IBMDADB2; DSN=" & strDBName
If strUserName <> "" And strPassword <> "" Then
strConnectionString = strConnectionString & "; User ID = " & strUserName & "; Password=" & strPassword
End If
'a = 2
'If a = 2 Then
' strConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Password=tel589;User ID=strtel;Data Source=DB2ADMIN"
'Else
' strConnectionString = "Provider=IBMDADB2.1;Password=tel589;User ID=strtel;Data Source=DB2ADMIN;Persist Security Info=True"
' 'strConnectionString = "Provider=MSDASQL.1;Password=tel589;Persist Security Info=True;User ID=strtel;Data Source=DB2ADMIN;Mode=ReadWrite"
'End If
' Create new ADO connection object
Dim adoConnection As New ADODB.Connection
With adoConnection
.CursorLocation = adUseClient
.ConnectionString = strConnectionString
End With
' Return new ADO connection object
Set GetConnection = adoConnection
Set adoConnection = Nothing
Exit Function
GetConnection_ErrHandler:
'MsgBox "Error Code: " & Err.Number & vbNewLine & "Description: " & Err.Description & vbNewLine & "Source: " & Err.Source, vbOKOnly, vbCritical
Err.Clear
Set GetConnection = Nothing
End Function
|