Connect Excel to Multiple sessions of Teradata, possible?

Dr Zenith

New Member
Joined
Mar 14, 2011
Messages
18
Hey Guys...

I am not connecting excel to teradata through ADODB connection and getting the results in the recordset.

The thing is, I have a slew of SQL's to be run around (10-15) which need not be sequentially. Using the below method, I am able to run each SQL query one after the other,

My question is, if it is possible to connect to multiple sessions of teradata and submit multiple SQL queries at once?

I am using the following template to run my SQL's one at a time now, please suggest a better method.

Code:
Sub try()


    Dim cnnTeradata As ADODB.Connection
    Dim connstr As String
    Dim adoconn As New ADODB.Connection
    Set cnnTeradata = CreateObject("ADODB.Connection")
    cnnTeradata.Properties("Prompt") = 1
    cnnTeradata.Open
    cnnTeradata.CommandTimeout = 50000000
    Set adoconn = cnnTeradata
    connstr = adoconn.ConnectionString
    Application.EnableCancelKey = xlDisabled 'Eliminates "Code Execution has been interrupted" Error
  
    ' Exports data from the Teradata to a active worksheet
    '--------------------------------------------------------------------------------------
    Dim db As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Application.ODBCTimeout = 0
    db.ConnectionString = connstr
    db.CommandTimeout = 5000
    db.ConnectionTimeout = 5000
    db.Open
    
                sql1 = "Sel * from table"
        sql2 = "Sel * from table1"
        sql3 = "Sel * from table2"
                With rs
                    .ActiveConnection = db
                    .LockType = adLockOptimistic
                    .CursorType = adOpenKeyset
                    .Open sql1
                     Range("B10").CopyFromRecordset rs
                    rs.Close            'Closes the Recordset object
                End With
                
                With rs
                    .ActiveConnection = db
                    .LockType = adLockOptimistic
                    .CursorType = adOpenKeyset
                    .Open sql2
                     Range("B11").CopyFromRecordset rs
                    rs.Close            'Closes the Recordset object
                End With
                
                With rs
                    .ActiveConnection = db
                    .LockType = adLockOptimistic
                    .CursorType = adOpenKeyset
                    .Open sql3
                     Range("B12").CopyFromRecordset rs
                    rs.Close            'Closes the Recordset object
                End With  
            Set rs = Nothing
            Set cnnTeradata = Nothing
            Set adoconn = Nothing
            db.Close
            Set rs = Nothing
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Duh, I can't seem to edit my earlier post....the first line should read as

"I am connecting excel to teradata through ADODB connection and getting the results in the recordset."
 
Upvote 0

Forum statistics

Threads
1,225,399
Messages
6,184,755
Members
453,254
Latest member
topeb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top