HOWTO: Setup SQL Server Linked Server to MySQL

In: SQL Server
Written by: Taylor Gerring


25 Feb 2009

Despite being completely proprietary, one of the nice connectivity features offered in SQL Server is the ability to query other servers through a Linked Server. Essentially, a linked server is a method of directly querying another RDBMS; this often happens through the use of an ODBC driver installed on the server. Fortunately, many popular databases provide this ODBC driver, giving SQL Server the ability to connect to a wide range of other systems. I’ve already written about how to connect Oracle and SQL Server. In this post, I’m going to go through the steps necessary to connect SQL Server and MySQL.

The first step is to fetch an appropriate MySQL Connector/ODBC 5.1 download. Drivers are available for a variety of OS‘s, but we’re obviously focused on Windows or Window x64, which should correspond to the version of SQL Server installed. After you’ve downloaded and installed the driver, we have a few things to configure, so let’s get started:

Configure a MySQL DSN

The first step is to configure a MySQL data source by running the ODBC Data Source Administrator. This step is technically entirely optional, but allows a simpler configuration in the SQL Server Linked Server settings. Instead of composing a complicated MySQL connection string, we can use a simple GUI application.

Run odbcad32

Run odbcad32

If you’re using Windows Server 2003, bring up a Run dialog box with Start→Run or WinKey+R. If you’re using Windows Server 2008, use the Start Menu search box directly. In either OS, type in “odbcad32″ and hit Enter.

System DSN

System DSN

Select the System DSN tab to configure a data source for the entire system. If you only want to create the DSN for a specific user (such as your service account), use the User DSN tab. In either scenario, select the “Add…” button.

Create New Data Source

Create New Data Source

Scroll down in the Create New Data Source window and select “MySQL ODBC 3.51 Driver” and click “Finish”.

MySQL Connector Login Settings

MySQL Connector Login Settings

Once added, clicking the “Configure…” button will bring up the Connector/ODBC 3.51 Configure Data Source application. This is where you can specify all the connection settings for connecting SQL Server to MySQL. Select a Data Source Name – I typically name it after the application or database I’m connecting to. The Server, User, Password, and Database should all be obvious.

Test ODBC Connection

Test ODBC Connection

After you’ve entered all the required parameters, click the “Test” button to ensure a connection can be made to the MySQL server.

These settings are the bare minimum required to connect MySQL and SQL Server via a linked server, but I like to specify additional options to optimize the connection between the servers. Without these, I have run into “Out of Memory” errors that require restarting the service.

MySQL Connector Advanced Flags 1 Settings

MySQL Connector Advanced Flags 1 Settings

Select the Advanced tab and you’ll be placed on the “Flags 1″ sub-tab. Check the boxes labeled “Allow Big Results” and “Use Compressed Protocol”.

MySQL Connector Advanced Flags 2 Settings

MySQL Connector Advanced Flags 2 Settings

Next, switch to the “Flags 2″ tab and select “Don’t Cache Result (forward only cursors)”. This can actually be a performance penalty if you perform the same query multiple times to the same linked server. However, in my experience, the reason to connect SQL Server to MySQL, is to pull data into a single server, in which case, this option is perfectly suited.

MySQL Connector Advanced Flags 3 Settings

MySQL Connector Advanced Flags 3 Settings

On the “Flags 3″ tab, select “Force Use Of Forward Only Cursors”. When you’re done setting all these options, select the “Ok” button.

Configure Linked Server Provider

Adjusting the Linked Server Provider is simple, but it comes with a caveat: When adjusting a provider, you are adjusting it for all connections using that provider. I am not aware of any way to change these settings on a per-connection basis.

Provider Properties

Provider Properties

Drill down to Server Object → Linked Servers → Providers, right-click MSDASQL, and select “Properties”.

Set Provider Options

Set Provider Options

The Provider Options for Microsoft OLE DB Provider for ODBC Drivers dialog box will open allowing you to configure several options. Ensure the following four options are checked:

  • Nested queries
  • Level zero only
  • Allow inprocess
  • Supports ‘Like’ Operator

All other options should be unchecked. When done, click “OK”.

Create Linked Server to MySQL

Finally, the last step in our process is to create the actual MySQL Linked Server.

Create a New Linked Server

Create a New Linked Server

You should already have Linked Servers expanded in the Object Explorer tree. If not, find it in Server Objects → Linked Server. Once there, right-click Linked Servers and select “New Linked Server…”

New linked Server Settings

New linked Server Settings

The New Linked Server dialog box will open. Because we specified all our connection settings in the ODBC Data Source Administrator, this last step is very simple. Name the linked server. As with the Data Source Name, I like to name it after the product or database I’m connecting to. In my example, I used MYSQLAPP. Ensure that the “Other data source” option is selected and choose “Microsoft OLE DB Provider for ODBC Drivers” from the Provider dropdown. Lastly, specify the Product name and Data source. The Product name doesn’t matter so much as the Data source must match what you provided in the MySQL Connector/ODBC configuration. Press “OK” when complete.

Testing the SQL Server to MySQL connection

If everything has been set correctly, you should be able to execute a query directly again the MySQL database from SQL Server Management Studio. For example:

SELECT TOP 10 TABLE_NAME FROM MYSQLAPP...tables WHERE TABLE_TYPE != 'MEMORY'

If you’ve done everything correctly, you should get back a result set. There are several error message you might receive:

OLE DB provider "MSDASQL" for linked server "MYSQLAPP" 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 "MYSQLAPP".

The message indicates that the Data source name you’ve specified for the linked server does not match that of the Data Source Name specified in the MySQL Connector.

Msg 7313, Level 16, State 1, Line 1
An invalid schema or catalog was specified for the provider "MSDASQL" for linked server "MySQLApp".

This uninsightful error is a result of not correctly setting the options for the Linked Server Provider.

Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "MySQLApp" reported an error. The provider did not give any information about the error.
Msg 7312, Level 16, State 1, Line 1
Invalid use of schema or catalog for OLE DB provider "MSDASQL" for linked server "MySQLApp". A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog or schema.

This “four-part name” error is due to a limitation in the MySQL ODBC driver. You cannot switch catalogs/schemas using dotted notation. Instead, you will have to register another DSN and Linked Server for the different catalogs you want to access. Be sure and follow the three-dot notation noted in the example query.

If, however, you want to access other schemas, you can do so utilizing OPENQUERY. This is also a great way to test your connection if you’re receiving problems. The syntax looks like this:

SELECT * FROM OPENQUERY(MYSQLAPP, 'SELECT * FROM INFORMATION_SCHEMA.TABLES LIMIT 10')

Notice that the actual query syntax in the string must be in the MySQL format (SQL Server does not support the LIMIT keyword). Additionally, you can specify a different schema using SCHEMA.TABLENAME in the query.

Conclusion

Creating a linked server between SQL Server and MySQL is a simple process. The first time requires you to install the software and configure the Linked Server Provider, but all subsequent connections require only a DSN and Linked Server.

70 Responses to HOWTO: Setup SQL Server Linked Server to MySQL

Avatar

Mike McLoughlin

April 3rd, 2009 at 2:04 am

We tries this but are getting an error you have not mentioned.

Msg 7399, Level 16, State 1, Line 3
The OLE DB provider “MSDASQL” for linked server “test3″ reported an error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Line 3
Cannot initialize the data source object of OLE DB provider “MSDASQL” for linked server “test3″.

Any ideas?

Avatar

Taylor Gerring

April 3rd, 2009 at 11:53 am

What happens if you try to run a query using OPENQUERY? For example,

SELECT * FROM OPENQUERY(test3, 'SELECT * FROM INFORMATION_SCHEMA.TABLES LIMIT 10')

Avatar

Eric Dossey

April 6th, 2009 at 2:29 pm

Thanks,

this was very helpfull and worked great.

EricD

Avatar

Greg

May 5th, 2009 at 4:03 pm

hey,

this has been very helpful, but i keep getting error 7303…
I doubled checked the DNS name I gave my odbc connection. but still no success. do we need the “provider string?

greg

Avatar

Taylor Gerring

May 5th, 2009 at 4:17 pm

@Greg

I would check two things:
1. Test the ODBC connection you setup in the MySQL Connector. Just hit the “Test” button and verify that the connection succeeds.
2. Copy and paste the “Data Source Name” from the connector to the Linked Server Data Source to ensure you have no typos.

If you still have a problem, try expanding the Linked Server and drilling down through the catalog and tables to see if you have access.

Let me know how that goes for you. If all else fails, you can still try and specify an absolute connection string.

Avatar

BigBen

May 6th, 2009 at 3:46 pm

I had to set the absolute connect string to get this to work.
installing the ODBC driver and configuring the system DSN in Data sources was straightforward (and yes, be sure to hit the TEST Connection button when configuring the ODBC source).

Other docs on the MySQL site all pointed to the absolute connect string, and once I entered that, all was well.

Avatar

alegorn

May 11th, 2009 at 10:35 pm

I had the same error. The problem was solved by installing the 5.1 driver and using connection string, without ODBC. Connect through ODBC I have not succeeded, although Access takes the data source.

Avatar

Latest sql server keyword news - HOWTO: Setup SQL Server Linked | Keyword Suggestion Tools

May 26th, 2009 at 8:32 pm

[...] HOWTO: Setup SQL Server Linked Server to MySQL [...]

Avatar

Executing MySQL Stored Procedures from SQL Server | youdidwhatwithtsql.com

June 8th, 2009 at 2:02 pm

[...] Configure your MySQL Server as a Linked Server in SSMS. Plenty of guides on the net about this so I won’t repeat it here. Here’s good one. [...]

Avatar

Arthur Fuller

June 9th, 2009 at 9:35 am

Your article was very timely, as I’ve recently been pondering this approach. However, your focus is on querying the linked server. Can one also write to the MySQL database using this technique? That’s what I want to do — write all the data from a SQL Server database to a corresponding MySQL database. Can this be done? If so, then I could set up an SSIS package to perform the task according to a schedule.

Thanks.

Avatar

Simon

June 10th, 2009 at 3:29 pm

Thanks for this post – Very useful!

Avatar

Taylor Gerring

June 10th, 2009 at 3:36 pm

@Arthur Fuller
You shouldn’t have any issues performing writes back to MySQL.

Avatar

mkoenings

July 15th, 2009 at 8:20 am

works great, even on a 64bits 2003 Server with SQL Server 2008
Thanks a lot!

Avatar

Bogdan

July 20th, 2009 at 9:39 am

Great Post!

Now can really get data from the DSN that I had to create.

I like Linked Server from SQL Server 2005. :D

100nx!

Avatar

Luca Zavarella

August 12th, 2009 at 6:49 am

Do you have issues like “Unable to begin a distributed transaction” using ON INSERT triggers? If not, how did you solved this problem?

Thank you in advantage.

Avatar

S Mummert

September 3rd, 2009 at 10:10 am

Dangling Connections – has anyone seem the number of connections increase from the server that is linking to the mySQL? We have limited the app server connection pool to 30 connections (cold fusion) but the number keeps growing. It seems like the connection to mySQL, managed by MDAC is not flushing and closing the connections correctly hence the number of connections keeps increasing with every call.

Any thoughts? We are in 64 bit SQL 2008 with 64 bit 2003 OS. My SQL is 5.1

Avatar

David Saacke

September 10th, 2009 at 1:42 pm

Thanks for the post. Had an issue with ODBC recognition…we’re MS SQL Server 2008, 64-bit but I had to configure the 32-bit ODBC (was not recognizing 64-bit).

Issue I have now – Linked server succeeds but I cannot see any of the tables (literally, from Mgmt Studio when I try to branch out the Table listing, none appear). When I try to query, object does not exist. I don’t think this is a priv issue on my mysql db – but not sure how to get tables to appear.

Any advice appreciated

Avatar

sensei

November 2nd, 2009 at 11:56 am

This method works, but it sucks because it can only return a max of 2 rows. this is a broken mechanism. not the method, but mysql.

its a good db, but it needs a lot more work to make it to the big time.

Avatar

Keith

November 6th, 2009 at 7:35 am

Thanks for this how-to.
Maybe you can help me with an issue I am facing.
I have established a link between MS SQL 2000 and MySQL. I have successfully queried the MySQL database from MS SQL Analyzer.

Now I would like to store passwords on the MySQL table using the MySQL “AES_ENCRYPT()” function. (using MS SQL Analyzer) Can this be done? and if so how?

Avatar

Taylor Gerring

November 6th, 2009 at 9:47 am

@Keith
You have a few different options:

1. Implement an AES Encrypt function on SQL Server and pass it through already encrypted. This is a bit harder since You’re on SQL Server 2000.
2. Pass the plaintext to a stored procedure on MySQL and have that proc encrypt it locally.
3. See if you can’t get INSERT OPENQUERY() to work with a remote function. I tried and couldn’t figure out if this is even possible due to the syntax.

Avatar

Keith

November 6th, 2009 at 10:03 am

>2. Pass the plaintext to a stored procedure on MySQL and have that proc encrypt it locally.

Any thoughts on how to pull this off?

Avatar

Troy

December 8th, 2009 at 6:22 am

Hi there,

I’ve tried to setup the DSN connection but when I try a test I get this msg – connection failed: [HY000][MYSQL][ODBC 5.1 Driver]Unknown MySQL server host.
I’m trying to connect my SQL server 2005 to a hosted MYSQL Dbase.
Not sure where to start?
any help would be great.
thanks

Avatar

Taylor Gerring

December 8th, 2009 at 1:55 pm

@Troy

It seems like it can’t even find the MySQL server. Ensure that traditional connections work before trying something un-interactive as Linked Servers. MySQL Query browser would be a good place to start.

My guess is that outside connections to the hosted MySQL instance are blocked by default.

Avatar

Dustin

January 4th, 2010 at 12:30 pm

Hello,

Great post. Got anything on random column errors when running select statements against the linked server? Such as..

Msg 7342, Level 16, State 1, Line 1
An unexpected NULL value was returned for column “[MSDASQL].TIMESTAMP_COL” from OLE DB provider “MSDASQL” for linked server “DB_LINK”. This column cannot be NULL.

OR

Msg 7347, Level 16, State 1, Line 1
OLE DB provider ‘MSDASQL’ for linked server ‘DB_LINK’ returned data that does not match expected data length for column ‘[KBOX_DB_LINK]…[TABLENAME].COL1′. The (maximum) expected data length is 14, while the returned data length is 8.

Thanks ahead of time.

Avatar

Ben

January 4th, 2010 at 9:55 pm

I keep running into a funny issue with my Linked Server setup. If I have the “Don’t cache results” and “Force forward only cursors” options checked, any time I run an insert I get:
“OLE DB provider “MSDASQL” for linked server “test” returned message “[MySQL][ODBC 3.51 Driver][mysqld-5.0.77-log]Commands out of sync; you can’t run this command now”.”

I can run the inserts without these options checked but after some time the MySQL server returns an “Out of Memory” error (which I imagine is do to it caching results). Anyone have some insights into this?

Avatar

Ben

January 5th, 2010 at 8:30 am

@Dustin, in my experience is usually do to an invalid date in the MySQL DB. MySQL allows for some none existant dates such as 0000-00-000, 1999-00-00 or 2010-01-00, all of which SQL Server will choke on. Also, T-SQL datetime limits it to dates after year 1753, though this shouldn’t matter in most cases.

Avatar

Ben

January 5th, 2010 at 8:33 am

@Dustin, in my experience that error usually has to do with an invalid date in the MySQL DB. MySQL allows for some non-existent dates such as 0000-00-000, 1999-00-00 or 2010-01-00, all of which SQL Server will choke on. Also, T-SQL datetime limits it to dates after year 1753, though this shouldn’t matter in most cases.

Avatar

John

January 13th, 2010 at 10:08 am

Great article, but I seem to have an issue with the MSDASQL provider does not show up in SQL Server Management Studio… Any thoughts?

Avatar

John

January 13th, 2010 at 10:13 am

Nevermind – I found the issue. I needed to install the following hotfix from Microsoft:
http://www.microsoft.com/downloads/details.aspx?FamilyID=000364db-5e8b-44a8-b9be-ca44d18b059b&displaylang=en#filelist

Avatar

Edward

January 15th, 2010 at 3:51 am

I’ve defined MySQL as a linked server and this is working fine. However, I’m having problems with diacritical charaters. For example the name André is displayed as André. MySQL is in utf8. Using the MySQL Query Browser gives the same result. However, if I first use ‘set character_set_results = NULL’, the name is displayed correct. How can I do this in MSSQL using the linked server?

Thanks in advance.

Avatar

DaveC

January 29th, 2010 at 3:46 am

I’m trying to link a MYSQL database (held on a LINUX server) as a linked server through SQL Server 2005.

I have installed all the relevant software – ODBC MYQL drivers (latest version) and have set up an ODBC DNS which seems to connect with no problems. I have also set up the linked server which enables me to see the MYSQL database and expand to the tables, however i can’t see any tables, the folder is empty.

This seems to me like its a priovelege issue within MYSQL, howevere all the priveleges seem okay and look like they are setup to see SQL server 2005 user.

Can anyone shed any ligtht on this?

Could it be something to do with it being on a LINUX server?

Thanks in advance.

Avatar

ChrisC

February 5th, 2010 at 7:11 am

Does anyone have information on linking SQL2005 with a SQLite sever?

Avatar

ben

February 23rd, 2010 at 5:42 pm

I used this process and it worked great – however the only problem that I had was when I would run a query through MS SQL it would crash. This was due to the 32-bit overflow from MS SQL. To solve it follow this process in “Flag 3″ – Checked the option “Limit Column Size to 32-bit range”

Hope this helps anyone that is having problems. Thanks again for the great article

Avatar

How do I "create linked server"? - dBforums

June 2nd, 2010 at 10:12 pm

[...] nothing on how to connect this to that, I looked up several references to help me out. Among them: HOWTO: Setup SQL Server Linked Server to MySQL | Idea Excursion Welcome onboard – Microsoft SQL Server: Configuring Linked Server from SQL Server to MySQL I [...]

Avatar

Ross

June 8th, 2010 at 3:59 am

Thank you very much for this article! I was really struggling until I found your notes. I was able to connect MySQL 5.1.41 to SQL Server Express 2008 R2 succesfully on WindowsXP using your method.

Avatar

Architecture Mismatch In Connection Between SQL 2008 and MySQL ODBC

June 16th, 2010 at 11:39 am

[...] of you looking for additional help on how to configure a linked server connection to MySQL, see HOWTO: Setup SQL Server Linked Server to MySQL and How to create a Link Server for mySQL in SQL Server Management Studio (SSMS) in SQL Server [...]

Avatar

GhostRider

June 18th, 2010 at 10:45 am

When I do a right click to create a Linked Server in sql 2008 in the :- Provider drop down box I do NOT see a selection for :- Microsoft OLE DB Provider for ODBC Drivers.

Would be grateful if some one could please tell me why this might be

Regards

Ghost

Avatar

Robert

June 22nd, 2010 at 1:48 pm

I followed the instructions and can drill down on the linked server and see tables. However, if I try a select or even try to script a select from the management studio I get an error. 7306….

I connect with the same credentials from other query tools and the linked server does show the tables…

Any ideas?

Avatar

Jaspal Sran

July 13th, 2010 at 1:55 am

Sir , After configuring linked server, when i execute the query then system shows the error message. Please guide me.

OLE DB provider “SQLNCLI” for linked server “Jas” returned message “Invalid authorization specification”.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider “SQLNCLI” for linked server “Jas” reported an error. Authentication failed.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider “SQLNCLI” for linked server “Jas”.

Avatar

Akansha

July 21st, 2010 at 7:46 am

i hav installed mysql connector/odbc 5.1.6..it has been nstalled successfully..but wen i open the data source(odbc) to create DSN, i do not find the myql driver that i had installed…can u please help me??

Avatar

Taylor Gerring

July 21st, 2010 at 10:21 am

If you’re on a 64-bit OS, did you run the 32-bit version of ODBC applet? Run: odbcad32

Avatar

Winkey

July 22nd, 2010 at 10:30 pm

I’ve created a linked server for mysql successfully, and also can do Insert, Select. But when I try to insert into mysql in TRIGGER, it give out an error:

OLE DB provider “MSDASQL” for linked server “MYSQL” returned message “[MySQL][ODBC 5.1 Driver]Optional feature not supported”.
Msg 7391, Level 16, State 2, Procedure msg_insert, Line 17
The operation could not be performed because OLE DB provider “MSDASQL” for linked server “MYSQL” was unable to begin a distributed transaction.

Avatar

Prakash - Savvysoft Technologies

August 6th, 2010 at 2:52 am

USE master
GO
– To use named parameters: Add linked server in the source (Local machine – eg: MachineName or LocalSeverLoginName)

sp_addlinkedserver
@server = N’LnkSrv_RemoteServer_TEST’,
@srvproduct=N”, — Leave it blank when its not ‘SQL Server’
@provider=N’SQLNCLI’, — see notes
@datasrc=N’RemoteServerName’,
@provstr=N’UID=sa;PWD=sa;’
–,@catalog = N’MYDATABASE’ eg: pubs
GO

/*
Note:
To check provider name use the folling query in the destination server
Select Provider From sys.servers
*/
———————————————————————————————————-
– Optional
–EXEC sp_addlinkedsrvlogin ‘LnkSrv_RemoteServer_TEST’, ‘true’ — (self is true) — for LocalSeverLoginName
–GO

– Remote login
sp_addlinkedsrvlogin
@rmtsrvname = ‘LnkSrv_RemoteServer_TEST’,
@useself = ‘False’,
@rmtuser = ‘sa’,
@rmtpassword = ‘sa’
GO

– OR
/*
IF the above add linked server login failed then try in the Linked Server (LnkSrv_RemoteServer_TEST) Property
Select -> Security – > ‘For a login not defined in the list above, Connection will:’

Choose – > Be made using this security context
SET Remote login: sa
With password: sa
*/
———————————————————————————————————-

– Test server connection
declare @srvr nvarchar(128), @retval int;
set @srvr = ‘LnkSrv_RemoteServer_TEST’;
begin try
exec @retval = sys.sp_testlinkedserver @srvr;
end try
begin catch
set @retval = sign(@@error);
end catch;
if @retval 0
raiserror(‘Unable to connect to server. This operation will be tried later!’, 16, 2 );

– OR

BEGIN TRY
EXEC sp_testlinkedserver N’LnkSrv_RemoteServer_TEST’;
END TRY
BEGIN CATCH
PRINT ‘Linked Server not available’;
RETURN;
END CATCH
———————————————————————————————————-

– Get access linked server database
SET xact_abort ON
GO

BEGIN TRANSACTION
SELECT * FROM LnkSrv_RemoteServer_TEST.DBName.dbo.tblName
COMMIT TRAN
GO

– OR
SELECT * FROM OPENQUERY(LnkSrv_RemoteServer_TEST, ‘SELECT * FROM DBName.dbo.tblName’)
GO

– OR
SELECT * FROM OPENQUERY(LnkSrv_RemoteServer_TEST, ‘SELECT * FROM sys.databases Order by name’)
GO
———————————————————————————————————-

Avatar

Yushe » Blog Archive » Conectar SQL Server con MySql

September 1st, 2010 at 10:20 pm

[...] Disclaimer: El árticulo arriba no es mio, es solo una traducción parcial del árticulo aqui [...]

Avatar

d_riz

September 29th, 2010 at 1:51 am

Very helpful. Thanks

Avatar

Saggy

October 15th, 2010 at 10:08 am

Absolutely brilliant article!

It didn’t work for me initially as I was using remote SQL server instead of local SQL server. Stupid me :)

Thanks again for your excellent article.

BTW, I was getting the following error (in case someone doing the same thing) -:

[OLE/DB provider returned message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified] OLE DB error trace [OLE/DB Provider 'MSDASQL' IDBInitialize::Initialize returned 0x80004005: ]

Avatar

Michael

October 26th, 2010 at 10:58 pm

Great article, I had used a similar article to setup SQL Server 2008 linked server to MySQL with MySQL Connector 5.1.6

Connection works great.

Queries work great.

Setup a Stored Procedure that populates a temporary table for reporting, works great.

Running reports from dev environment in Visual Studio works great.

Deploying and executing the report from Report Manager on the Report Server returns a generic message:

An error occurred during client rendering.
An error has occurred during report processing.
Query execution failed for dataset ‘spUMGAudioStreetdateCheckDataSet’.
For more information about this error navigate to the report server on the local server machine, or enable remote errors

Running the report from the Web Service gives a little more info:

An error occurred during client rendering.
An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for dataset ‘spUMGAudioStreetdateCheckDataSet’. (rsErrorExecutingCommand)
Cannot initialize the data source object of OLE DB provider “MSDASQL” for linked server “MYSQLPROD”.

Any ideas? I’ve got the MySQL Connector installed and the System DSN configured on both the SQL Server and Web Server. Testing the connection works fine in both places.

I’ve checked the MSDASQL properties as mentioned in this article. The only problem I have is trying to run a report from Reporting Services in Report Manager. Permissions are set the same as all other reports I am able to execute.

Cheers for any feedback!

Avatar

Michael

October 27th, 2010 at 10:02 pm

My God… I had failed to add the Reporting Services Browser User to the Linked Server Remote Server Login Mappings.

In the end I still deserve a head banging. Thanks for your ear though.

Avatar

HowTo: Setup SQL Server Linked Server to MySQL « Clint Huijbers's Blog

November 25th, 2010 at 4:31 am

[...] This week I had to create a linked server to a MySQL database on SQL Express (development environment)….whoohooo!…NOT But ok, it’s possible. Found this step-by-step blogpost. [...]

Avatar

Wayne Erfling (Cornan The Iowan)

January 4th, 2011 at 10:54 am

We’re getting the “four-part notation error with the 64-bit ODBC connector from SQL Server 2008 (64-bit), even though we’re NOT trying to “change the schema”.

We’re talking to exactly the same MySQL database. The only thing we did was to move to a SQL Server 2008 R2 / 64-bit database server.

I’d hate to lose four-part notation and be forced to write 100% of my queries using OPENQUERY.

Avatar

Tom DeMay

January 12th, 2011 at 11:29 am

I’m desperate. Anyone still there?

I had a linked server to mysql working perfectly. I ran a big job to export data from SQL Server to mysql at 3 am this morning. Went to bed and this morning got up to check on it. some data was missing. Started to troubleshoot problem and my linked server no longer works. Everyone in my office swears they didn’t do anything to the machine.

I’m getting OLE DB provider “MSDASQL” for linked server “REDMINE” returned message “[Microsoft][ODBC Driver Manager] Invalid connection string attribute”

but if I go to my ODBC driver and click test connection it works perfectly.

I tried recreating another ODBC driver and another linked server. ODBC driver works, but linked server does not. Only settings I made to linked server is
Provider: Microsoft OLE DB Provider for ODBC Drivers
Product Name: redmine
Data source: redmine

My system ODBC driver data source name is redmine

I’ve googled the h. e. double toothpicks out of this thing and can’t find anything. I enabled ODBC driver debug logging and the logging doesn’t show anything.

Avatar

Rick Young

January 12th, 2011 at 4:43 pm

Works great for most attributes. On some it gives and error that it expected 72 and got 2 on a field in MySQL of Char 36 datatype. Most are 36 chars but one or two are one char.

Any ideas?

Avatar

Taylor Gerring

January 12th, 2011 at 4:56 pm

@Tom Did you double-check the Provider configuration to ensure it didn’t get reset? Those settings stand for all links of that type, so creating a new Linked Server wouldn’t fix anything if this were the problem.

Avatar

kalyson

April 26th, 2011 at 2:02 pm

Ben said:

January 4th, 2010 at 9:55 pm

I keep running into a funny issue with my Linked Server setup. If I have the “Don’t cache results” and “Force forward only cursors” options checked, any time I run an insert I get:
“OLE DB provider “MSDASQL” for linked server “test” returned message “[MySQL][ODBC 3.51 Driver][mysqld-5.0.77-log]Commands out of sync; you can’t run this command now”.”
——————————————————————————

That “Commands out of sync” thing is most likely a bug in the MySQL ODBC driver. There is a work-around for it. Create the linked server like this instead:

EXEC master.dbo.sp_addlinkedserver @server = N’yourslinkedservername’, @srvproduct=N’MySQL’, @provider=N’MSDASQL’, @datasrc=N’yourdatasourcename’,
@provstr=’DRIVER={MySQL ODBC 5.1 Driver};SERVER=yourremoteservername;Port=3306;USER=yourremoteloginname;PASSWORD=yourremotepassword;DATABASE=yourremotedatabasename;’

You can edit the options for performance for the linked server in the GUI after it is created with this command. You can add the ‘Don’t cache result forward only cursors’ and all the other optimizations needed, as well as adding user names and passwords in the security tab (or add login/password using the sp_addserverlogin).

I tried it repeatedly and it worked great.

Got rid of that ‘Commands out of synch’ problem.

[BTW: I am connecting to a MySQL db on Ubuntu Linux using linked servers on SQL Server 2005 with driver MSADSQL]

Avatar

kalyson

April 26th, 2011 at 2:21 pm

As an aside, I did see that some types of tables still get the ‘commands out of sync’ error.

Dustin was right about the date fields – the queries work now on all except those with empty date fields in my remote MySQL db. If you do a select on such a table, you may get the same error as me:

“An unexpected NULL value was returned for column [...]‘

An insert on this table always produces some sort of error — generally the ‘out of sync’ error.

Avatar

kalyson

May 8th, 2011 at 6:45 pm

Yes it is true that if you edit the Data Source properties, you can get this

“commands out of sync,you can’t run this command now”

error to stop:

Administrative Tools -> Data Source (ODBC) ->

-> Configure -> Details -> Cursors/Results ->

We have not gotten the out of memory error, at least not yet!

The Date fields actually don’t seem to be consistently the root of the problem after all, Dustin. We started getting it on tables not having any date fields, too.

Avatar

sadhat

June 27th, 2011 at 3:55 am

Excellent work…. thumbs Up :) thank a lot.

Avatar

Vijay K Rathod

July 6th, 2011 at 7:04 am

Dear All,

I have one requirement, i need to pull the data from MySql(Linux machine) to MS-Sql Server 2000(windows server/machine), the process has to be done in windows machine, please help me out regarding this.

Avatar

bx

July 15th, 2011 at 10:20 am

Just doing:
Run > cmd > obdcad32

Didn’t get ‘er done…

I had to open 32 bit odbc connector by entering this in cmd:
C:\Windows\SysWOW64\odbcad32.exe

Avatar

John

July 25th, 2011 at 10:58 am

Good job on the instructions. Outside of having to install the MSDASQL onto the server and installing the 5.1 MySQL ODBC drivers. this instruction is good.

Another key to note, is that you need to verify that SQL version and ODBC driver version are the same, ie 32 or 64 bit. As well, verify if you have the normal 64 or itanium 64. there are not that much of a difference but their system library utilizes the processor differently. In regards to MYSQL ODBC there is no difference but in regards to MSDASQL there could be a potential conflict.

Avatar

John

July 25th, 2011 at 11:01 am

bx,
i hope you realized that you have a typo in your statement.

it is ‘odbcad32′ not ‘obdcad32′, and even then you could simply just go Programs -> Administrative Tools -> Data Sources (ODBC) to access your panel.

————————————–
Response:
bx

July 15th, 2011 at 10:20 am

Just doing:
Run > cmd > obdcad32

Didn’t get ‘er done…

I had to open 32 bit odbc connector by entering this in cmd:
C:\Windows\SysWOW64\odbcad32.exe

————————————–

Avatar

Lin

October 5th, 2011 at 2:22 pm

For those having below error, just try to replace mySQL name from FQDN to IP, it worked, don’t know why.

Cannot initialize the data source object of OLE DB provider “MSDASQL” for linked server “test3?

Avatar

Victor

November 14th, 2011 at 9:50 pm

Taylor, Hoping to get some help from you. I am good all the way up to setting the ODBC driver and with test connection successful. But when i try to Create Linked Server to MySQL, I got this error:
The OLE DB Provider “SQLNCLI10″ for linked Server “MYSQLAPP” reported an error.
Cannot initialize the data source object of OLE DB provider “SQLNCLI10″ for linked server “MYSQLAPP”
OLE DB Provider “SQLNCLI10″ for linked server “MYSQLAPP” returned message “invalid authorization sepcification”. )Microsoft SQL Server Error 7399)

I am using SQLEXPRESS 2008 on my laptop and window authentication for password. There is no other user.
Any suggestion? thanks

Avatar

Taylor Gerring

November 15th, 2011 at 12:03 pm

@Victor

My inital feeling is that you need to connect with known valid credentials. If you’re using Windows Authentication, I’m not sure how MySQL could possibly know about that AD account.

Try adding a user to MySQL (don’t forget to issue a FLUSH PRIVILEGES) and validating that you can connect using native tools (i.e. phpMyAdmin, MySQL Workbench, etc.) Once that works, only then try to connect via Linked Server.

Avatar

Daniel Costa

November 16th, 2011 at 5:37 pm

Hello,

I find a solution to this, and I put it to my Blog:
http://blog.danielcosta.pt/?p=492

There is a problem using this driver, and with semicolon separated files.

Hope this help!

Daniel Costa

Avatar

Victor

November 26th, 2011 at 5:55 pm

@Taylor
You are awesome. THANK YOU!

Avatar

Waldon

December 15th, 2011 at 2:33 pm

I have been able to set up the ODBC data sourse(s), and they test OK. I have been able to configure the MSDASQL provider as indicated, and I have been able to create the linked server. I can open the catalog, database, and see the table names.

When I try to do a select, however, I just get errors:

Select * from LinkSrv1.DB1..table1

gives Msg 7399 …error. provider did not give info, and
Msg 7312, Invalid use of shema or catalog. Four part name supplied, but the provider does not expose the needed interface to use catalog or schema.

Select * from openquery(LinkSrv1, ‘Select * from LinkSrv1.DB1..table1′)

gives

OLE DB provider “MSDASQL” for linked server returned message … You have an error in your SQL syntax; … check for syntax near ..table1

and

Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider …

AND if I try Select * from LinkSrv1.DB1.table1

I get Msg 208 Invalid object name…

Any ideas?? All help is greatly appreciated.

Avatar

Waldon

December 15th, 2011 at 2:47 pm

Wow, just got it to work! Just had to use:

Select * from openquery(LinkSrv1, ‘Select * from DB1..table1?)

DUH.

Avatar

Leyla

December 30th, 2011 at 11:42 am

@Taylor : Thanks alot, it was so helpful and quick.

Avatar

Phil

January 10th, 2012 at 9:24 am

Thanks – this article was a great help.

Comment Form

@TaylorGerring


Unless specified otherwise, this website is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.
Stop SOPA
Unless specified otherwise, this website is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.