Search code examples
sqlexcelvbateradata

How connect to Teradata using VBA


I'm attempting to connect to Teradata through VBA:

Sub sql_query()

Dim Cn As ADODB.Connection
Dim Rc As ADODB.Recordset
Set Cn = New ADODB.Connection
On Error GoTo Invalid
Cn.Open "Driver={Teradata};DBCname=TDPREPE01;Uid=xxxx;Pwd=xxxxx!;"
Invalid:
MsgBox ("There was error number " & Err.Number & ". This is " & Err.Description & ".")

End Sub

I get the following error:
![enter image description here

I logged in with the correct credentials as it is the same credentials to login to mySQL.

Screenshot of my active connection:
enter image description here


Solution

  • The main point is to set an authentication or there will be no connection.

    The following worked:

    Sub sql_query()
    
    Dim Cn As ADODB.Connection
    Dim Rc As ADODB.Recordset
    Set Cn = New ADODB.Connection
    Cn.Open "Driver={Teradata};DBCname=TDPREP01;Uid=C121009;Pwd=Internet2022!; Authentication=LDAP;"
    

    End Sub