0

Everyone,

A VBA problem has been killing me the past two days. I have a Macro Based Model in Excel that has data sets bought into the spreadsheets from Oracle via OLEDB. To illustrate the problem simply I have created two functions within the Model. One using ODBC("odbc") and another using OLEDB("OraOLEDB"). The code was working completely fine last week and it has not been changed.

Now, however I get an error message that states "Run-Time Error '424': Object Required when I execute the line "conn.Open strCon" in sub "OraOLEDB".A connection can't be established with the database! So when I am trying to establish a connection to the database with that line of code, it fails. What is interesting is that via ODBC, a connection can be established. The line "conn.Open strCon" in sub "odbc" executes successfully and I am able to establish a connection to the database.

I did not change anything in the Excel Model but I did have a bunch of windows updates recently. I don't know if that corrupted anything. I think it may have. The reason why I don't want to use the ODBC connection is that it is significantly slower. I get run times 10x faster using OLEDB. Please let me know if you can help.


Sub odbc()
Dim conn As Object
Dim strCon As String

strCon = "Driver={Microsoft ODBC for Oracle}; 
          CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) 
             (HOST=xxx)(PORT=1521))
             (CONNECT_DATA=(SERVICE_NAME=xxx))); 
          uid=xxx;pwd=xxx;"

Set conn = CreateObject("ADODB.Connection")

conn.Open strCon

End Sub

Sub OraOLEDB()
Dim conn As Object
Dim strCon As String

strCon = "Provider=OraOLEDB.Oracle;
          Data Source=(DESCRIPTION =  (ADDRESS = (PROTOCOL = TCP)
             (HOST = xxx)(PORT = 1521)) 
             (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = xxx)));   
          User Id=xxx;Password=xxx"

Set conn = CreateObject("ADODB.Connection")

conn.Open strCon

2 Answers 2

2

I see the host for the OLEDB connection is modn-ast-fdb1. ... while for the ODBC connection you have modn-ast-tdb1. ... Shouldn't the host be the same?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mathguy. Change made.
1

This means Set conn = CreateObject("ADODB.Connection") returns nothing. Check ADODB.dll registration. Alternatively you may use

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

and you'll see if ADODB is available at the moment you edit the script not waiting for runtime errors.

2 Comments

Serg. Defining the variables this way fixed it. Thank you.
@jp3nyc: Please mark the answer that helped you best as accepted so that we the readers know exactly which answer solved your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.