Solved

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

Posted on 2014-01-06
15
6,727 Views
Last Modified: 2014-01-07
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.
0
Comment
Question by:akivashapiro
  • 8
  • 7
15 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39760259
You should be able to query MySQL using the OPENROWSET command:
SELECT <column_list> 
    FROM OPENROWSET(N'MSDASQL',N'Driver={MySQL ODBC 5.1 Driver};Server=myServer;Database=YourDB;User=YourUser;Password=xxxx;Option=3;', N'SELECT <column_list> FROM YourDB.YourTable LIMIT 1000')

Open in new window

You may have to modify the driver part to suit what you have installed on your system.
0
 

Author Comment

by:akivashapiro
ID: 39760413
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.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39760439
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?
0
 

Author Comment

by:akivashapiro
ID: 39760445
Same. I am running the query from within SQL Server Management Studio 2012 on the machine with the DB.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39760448
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.
0
 

Author Comment

by:akivashapiro
ID: 39760461
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?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39760497
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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:akivashapiro
ID: 39760539
It seems I had the 32 bit driver. I installed the 64 bit driver and it worked. Thanks.
0
 

Author Comment

by:akivashapiro
ID: 39763183
Hey Carl,

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

Thanks!
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39763215
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

0
 

Author Comment

by:akivashapiro
ID: 39763339
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.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39763402
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.
0
 

Author Comment

by:akivashapiro
ID: 39763436
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)".
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39763477
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?
0
 

Author Comment

by:akivashapiro
ID: 39763601
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.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now