VBA- Excel to Oracle DB Connection Issue

renithr

New Member
Joined
Mar 24, 2014
Messages
1
Hi All,

The below code to connect excel to oracle database is showing run time error.
Error at : src_conn.Open varConn

Did anyone phased this issue before?

Please let me know if anyone can resolve this issue.... :)

Code:
Private src_conn As ADODB.Connection
Private Rec_set As ADODB.Recordset
Sub Ora_Connection()

Dim OraSession As Object
Dim OraDatabase As Object
Dim EmpDynaset As Object
Dim flds() As Object
Dim fldcount As Integer

Set src_conn = New ADODB.Connection

varConn = "Driver={Microsoft ODBC for Oracle}; " & _
         "CONNECTSTRING=(DESCRIPTION=" & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=server)(PORT=1521))" & _
         "(CONNECT_DATA=(SERVICE_NAME=sname))); uid=uname;pwd=passwd;"

src_conn.CommandTimeout = 9999999
src_conn.Open varConn

Set Rec_set = New ADODB.Recordset
                
Sql = "select count(*) from table"
                 
Rec_set.Open Sql, src_conn
Dim mows As Worksheet

mows = ThisWorkbook.Worksheets("Sheet1")
With mows.QueryTables.Add(Connection:=Rec_set, Destination:=mows.Range(A1, B1))
                        .Refresh BackgroundQuery:=False
End With

End Sub
 
Last edited by a moderator:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
i dont see a parameter for database name in your varConn setup, is this required
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,527
Members
449,316
Latest member
sravya

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