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}; " & _
         "CONNECTSTRING=(DESCRIPTION=" & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=MyHOst)(PORT=1506))" & _
         "(CONNECT_DATA=(SERVICE_NAME=My_Service_Name))); uid=UID;pwd=Password;"

Open in new window


Thanks,
Montrof
LVL 1
montrofAsked:
Who is Participating?
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:
Hi

try this

cn.ConnectionString = "Driver={Oracle in OraClient11g_home1}; " & _
         "CONNECTSTRING=(DESCRIPTION=" & _
         "(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
    recset.MoveLast
    recordCount = recset.recordCount
    recset.MoveFirst
    Do While Not recset.EOF = True
         'Have a loop here to go through all the fields
        recset.MoveNext
    Loop
    recset.Close
End Sub
0

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.
0
montrofAuthor Commented:
I am getting the following error [Microsoft][ODBC Driver Manager] The Specific DSN contains an acrhitecture mismatch between the driver and Application
0
Kanti PrasadCommented:
Hi

use the 32-bit odbcad32.exe to configure or remove the DSN.
https://msdn.microsoft.com/en-us/library/ms712362(VS.85).aspx
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.