View Full Version : [SOLVED] ODBC connection error through VBA in excel

07-07-2018, 10:51 AM

I have created ODBC connection and trying to test ODBC connection in excel through VB.

ODBC DSN is tested and working.But when I use same DSN in VB script, it says invalid user name/password error.

Can any on let me know what is missing here.

Sub OraConn()
'Dim cnn As ADODB.Connection
'Set cnn = New ADODB.Connection
'Open a Connection using an ODBC DSN

Dim cnn As Object
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "D_DSN", "ro_user", "xxxx"

If cnn.State = adStateOpen Then
MsgBox "Welcome"
MsgBox "Sorry."
End If

' Close the connection.
End Sub

Thanks in advance

Jan Karel Pieterse
07-09-2018, 08:21 AM
Turn on the macro recorder and then manually connect to that connection. That should get you the syntax (more or less).