0

As the title states I'm trying to connect to an oracle DB for a vba script.

I was using this article here on how to do it: https://blogs.perficient.com/2015/12/17/connectcompare-databases-excel-macro/

I just have very basic code for connecting and I'm getting an error that says "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

My code is:

Private Sub CommandButton1_Click()
    Dim dbConnection As ADODB.Connection
    Dim recordSet As ADODB.recordSet
    Set dbConnection = New ADODB.Connection
    Set recordSet = New ADODB.recordSet
    conString = "Driver = {Microsoft ODBC for Oracle};DBQ=####;Uid=<####>;Pwd=<####>;"
    dbConnection.Open (conString)

End Sub

One thing I am not sure on is what exactly is DBQ is. I have set DBQ to the name of the database I'm interested in. Not sure if I'm setting that parameter properly.

Thank you and all help is appreciated it.

5
  • what version of oracle? Do you have an Oracle client installed? Commented Mar 13, 2020 at 14:35
  • Java(TM) Platform 1.8.0_221 Oracle IDE 19.4.0.354.1759 Microsoft ODBC for Oracle 10.00.17763.01 Hope that helps, or did you mean something else? Commented Mar 13, 2020 at 14:38
  • What version of the Oracle database? 12? 19? Commented Mar 13, 2020 at 14:40
  • Instead of DBQ try using Server. See this link for details. Commented Mar 13, 2020 at 14:47
  • Hi! sorry about that, I am using Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production Commented Mar 13, 2020 at 14:48

2 Answers 2

3

First question: Did you install an Oracle Client on your machine?

According to your connection string you use the Microsoft ODBC for Oracle driver. Connection string must be like this:

Driver={Microsoft ODBC for Oracle};Server=myServerAddress;Uid=myUsername;Pwd=myPassword;

Note, the connection string is slightly different to the Oracle ODBC driver, see ODBC Driver Microsoft vs. ODBC Driver Oracle

Second question: Is your Excel 32-bit or 64-bit?

The Oracle Client and the ODBC driver must be the same architecture (i.e. 32-bit vs. 64-bit) as your Excel. The ancient Microsoft ODBC for Oracle driver exist only for 32-bit. If your Excel is 64-bit then you have to use the Oracle ODBC driver.

Another note, the default Oracle Instant client does not include the ODBC driver, you have to download and install the "ODBC Package", from Oracle Instant Client Downloads

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

Comments

0

There is a comment above to use this format which I believe is correct "DSN={MyDataSource};UID={MyUserID};PWD={MyPassword};SERVER={MyOracleServer}"

From the Microsoft documentation and here

2 Comments

Yo dumb question, but how would I find the "DSN" and "SERVER". I have SQL Developer open with the DB I'm interested in, but not sure where exactly I'd find that info.
DSN is used when you have defined the DSN in your "ODBC Administrator" tool. SERVER is used to name the database directly (which you also enter SQL Developer).

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.