RE: Dsn-less connection to informix
Posted in 1999
Hope this helps. I had to strip out junk, so it probably won't compile. It is designed to connect to the same database in three different instances. -- Option Explicit Public Enum DBNames Prod Test Devl End Enum Function DatabaseConnect(sUserid As String, _ sPasswd As String, _ database As DBNames, _ fKeepConnection As Boolean) As Boolean Dim env As rdoEnvironment Dim iRdoCountId As Integer Dim iRdoLoopId As Integer DatabaseConnect = True On Error GoTo ConnectError: Select Case database Case Prod msService = "sqlexec" mvarhost = "prod" msServer = "prod_tcp" Case Test msService = "sqlexect" mvarhost = "test" msServer = "test_tcp" Case Devl msService = "sqlexecd" mvarhost = "devl" msServer = "devl_tcp" End Select msConnect = "UID=" & sUserid & ";" & _ "PWD=" & sPasswd & ";" & _ "DB=db_name;" & _ "HOST=" & mvarhost & ";" & _ "SRVR=" & msServer & ";" & _ "SERV=" & msService & ";" & _ "PRO=onsoctcp;" & _ "Driver={Informix-CLI 2.5 (32 BIT)};" & _ "DSN='';" Set env = rdoEnvironments(0) 'env.CursorDriver = rdUseOdbc env.CursorDriver = 0 Set mvarinfxconn = env.OpenConnection("", rdDriverNoPrompt, , msConnect) If Not fKeepConnection Then mvarinfxconn.Close Set mvarinfxconn = Nothing End If Exit Function ConnectError: ' Found error return a false DatabaseConnect = False ' We need to loop thru all of the rdo errors to determine what went wrong For iRdoLoopId = 0 To rdoErrors.Count - 1 If rdoErrors(iRdoLoopId).Number = -951 Then MsgBox "Invalid user id", vbExclamation, "SA_Login" Else If rdoErrors(iRdoLoopId).Number = -952 Then MsgBox "Invalid password entered", vbExclamation, "SA_Login" Else If rdoErrors(iRdoLoopId).Number <> 0 Then Err.Raise rdoErrors(iRdoLoopId).Number, _ "CLogin.DatabaseConnect ", _ rdoErrors(iRdoLoopId).Description End If End If End If Next iRdoLoopId ' If we didn't raise an error, then just continue Resume Next End Function