ADODB.Connection.Open error "[Microsoft][ODBC Driver Manager] Data source name..."

SeanDamnit

Board Regular
Joined
Mar 13, 2011
Messages
151
I'm trying to familiarize myself with VBA and SQL, here's what I have so far based on some examples I've seen out there:

Rich (BB code):
Sub GetDataFromADO()
    'Declare variables'
        Set objMyConn = New ADODB.Connection
        Set objMyRecordset = New ADODB.Recordset
        Dim strSQL As String

    'Open Connection'
        objMyConn.ConnectionString = _
           "OLEDB;Provider=SQLOLEDB;Password=xxxx;User ID=xxxx;Initial Catalog=master;Data Source=abc.com;"
        objMyConn.Open

    'Set and Excecute SQL Command'
        strSQL = _
        "SELECT iQclerk_Stores.Abbreviation, LanguageTranslations_2.FieldText AS 'Location' " & _
        "FROM ArchTelecom.dbo.iQclerk_Stores iQclerk_Stores, ArchTelecom.dbo.LanguageTranslations LanguageTranslations_2 " & _
        "WHERE iQclerk_Stores.StoreNameID = LanguageTranslations_2.ReferenceID AND ((iQclerk_Stores.Abbreviation='ALBN1'))"

    'Open Recordset'
        Set objMyRecordset.ActiveConnection = objMyConn
        objMyRecordset.Open strSQL

    'Copy Data to Excel'
        ActiveSheet.Range("A1").CopyFromRecordset (objMyRecordset)

End Sub

However, getting the following error on the "objMyConn.Open" line:

Rich (BB code):
Run-time error '-2147467259 (80004005)':

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Can anyone assist?

Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
That's caused by an error in your connection string, are you sure it's correct?

You wouldn't normally prefix a connection string like that with OLEDB; try:
Rich (BB code):
        objMyConn.ConnectionString = _
           "Provider=SQLOLEDB;Password=xxxx;User ID=xxxx;Initial Catalog=master;Data Source=abc.com;"
 
Upvote 0
That's caused by an error in your connection string, are you sure it's correct?

You wouldn't normally prefix a connection string like that with OLEDB; try:
Rich (BB code):
        objMyConn.ConnectionString = _
           "Provider=SQLOLEDB;Password=xxxx;User ID=xxxx;Initial Catalog=master;Data Source=abc.com;"

That worked. The OLEDB was there because that was what was recorded when I set up the connection string.

Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,215,268
Messages
6,123,966
Members
449,137
Latest member
yeti1016

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