VBA connection string to Oracle

I am trying to connect to Oracle through VBA.  I have an ODBC connection setup and it works but when I try to connect through vba it will not connect. The ODBC connection is called BBProd and using the Oracle in OraClient11g_home1 Driver.  

Here is my connection string vba
cn.ConnectionString = "Driver={Oracle in OraClient11g_home1}; " & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=MyHOst)(PORT=1506))" & _
         "(CONNECT_DATA=(SERVICE_NAME=My_Service_Name))); uid=UID;pwd=Password;"

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kanti PrasadCommented:

try this

cn.ConnectionString = "Driver={Oracle in OraClient11g_home1}; " & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=MyHOst)(PORT=1506))" & _
         "(CONNECT_DATA=(SERVICE_NAME=My_Service_Name))); uid=UID;pwd=Password;"

Here is an example

Sub GetData()
    Dim SQL_String As String
    Dim dbConnectStr As String
    Set con = New ADODB.Connection
    Set recset = New ADODB.Recordset
    Dim recordCount As Long
    dbConnectStr = "Provider=msdaora;Data Source=" & "Oracle_Database_Name;"
    User Id=userId" & "; Password=" & "password"
     'The statement above has been commented out. I use the statement below to prompt the user for the userId and password - which is what I prefer!
    con.ConnectionString = dbConnectStr
    con.Properties("Prompt") = adPromptAlways
    con.Open dbConnectStr 'ConnectionString
     'This is an example SQL code that you might want to run
     'Select * From MyTable
     'SQL_String = "Select count(*) from adm_user"
    recset.Open SQL_String, con
    recordCount = recset.recordCount
    Do While Not recset.EOF = True
         'Have a loop here to go through all the fields
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
montrofAuthor Commented:
It still will not connect I have built several connection before to SQL Server with no problem but I cannot get this one to work.
montrofAuthor Commented:
I am getting the following error [Microsoft][ODBC Driver Manager] The Specific DSN contains an acrhitecture mismatch between the driver and Application
Kanti PrasadCommented:

use the 32-bit odbcad32.exe to configure or remove the DSN.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.