Link to home
Create AccountLog in
Avatar of akivashapiro
akivashapiroFlag for Afghanistan

asked on

Connect to MYSQL/ODBC Table from SQL Server Management Studio 2012

Please let me know how to create a connection to a table via ODBC (or native if possible) from within SQL Server Management Studio 2012.

I want to be able to create a native SQL query in SQL Server that joins two tables, one from SQL Server and one from MYSQL without using a front end tool such as MS Access.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of akivashapiro

ASKER

Thanks very much. It looks like this has set me on the right track. I'm getting the following error when trying to connect:

SELECT *
    FROM OPENROWSET(N'MSDASQL',N'Driver={MySQL ODBC 5.1 Driver};Server=192.xxx.xx.xxx;Database=xxx_view;User=xxx_user27;Password=xxxx;Option=3;', N'SELECT * FROM xxx_view.abc LIMIT 1000')

OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".

I also tried MySQL ODBC 3.51 Driver.

Both are on my system under ODBC when I try to connect via MS Access.

Please let me know your thoughts.
This might be a daft question, but is SQL Server on the same machine you are running the query from, or is it on a separate server?
Same. I am running the query from within SQL Server Management Studio 2012 on the machine with the DB.
OK, as a test try adding your MySQL server as a linked server and see if it works that way. At least then you will be able to see what driver/provider details you need.
I've tried that as well, both through code and the interface. I've used the same string as above in Data Source field , and the error message returned is the same. Any other thoughts? Perhaps you know all the correct parameters for the interface?
I don't have a MySQL install to test this with at the moment - but try the provider as "MySQLProv" and see if that gets you any further.
It seems I had the 32 bit driver. I installed the 64 bit driver and it worked. Thanks.
Hey Carl,

Can you give me the OPENROWSET parameters for a local MSAccess accdb file please.

Thanks!
It should be something along the lines of:
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
   'c:\path_to_db\DbName.mdb';'username';'password', table_name) 

Open in new window

Here's what I get:

Msg 7302, Level 16, State 1, Line 1
Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

I have MS Access 2010 64-bit installed on the same system as sql server (and all of Office 2010 64-bit)

Should I open another question so you get credit for this additional work? If so, how I should I title it so you receive notification.
If it's 64-bit then try this as the provider instead 'Microsoft.ACE.OLEDB.12.0'  - I don't think there is a 64-bit Jet driver available.
Getting closer, I think. Here's what I get now:

OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Could not find installable ISAM.".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Can you post the connection as you currently have it? Also, did you try this through the linked server manager? Finally, is your Access DB a native 2010 one, or is it from an earlier version?
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','D:\EECO\E2T2.accdb', T1)

I was unable to properly configure linked server manager. It takes longer to troubleshoot, so I figured I would get OPENROWSET to work first, then use that to setup a linked server.

I created a new db "E2T2.accdb" in Access 2010 64 bit to be sure. But the only options under Access Options/General/Creating databases/Default file format for Blank Database are Access 2000, Access 2002 - 2003, Access 2007. I chose, of course, 2007, but I don't see how to create a "native 2010" db.