MS SQL Server and MySQL through Linked Server - mysql

We have MS SQL Server 2012 and MySQL 5.5, and we need to sync one table data between the two databases. So that whenever a record is inserted in the table "trainee" in MS SQL Server then it should directly copied to the table "trainee" in MySQL database.
We used the linked server, and it works fine for reading data from MySQL with the following driver:
MySQL ODBC 5.2 UNICODE Driver
And then we added a Trigger on the table in MS SQL Server with the following code:
USE [case]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[Inserttms]
ON [case].[dbo].[mdl_tms_trainee]
AFTER INSERT
AS
Insert into dbo.tms (id,u_id,trainee_number) Values ('8','8','888');
Further more, we enable the DTC in the server, set True for RPC and RPC OUT in the LInked Server, and even created aview in the local database in MS SQL Server in order to use workaround, but these all never solve the below problem.
OLE DB provider "MSDASQL" for linked server "TMSCASEU" returned message "[MySQL][ODBC 5.2(w)
Driver]Optional feature not supported".
Msg 7391, Level 16, State 2, Procedure Inserttms, Line 5
The operation could not be performed because OLE DB provider "MSDASQL" for linked server
"TMSCASEU" was unable to begin a distributed transaction.

Related

Update MySQl Linked server from sql server trigger

Error I get when I run
OLE DB provider "MSDASQL" for linked server "WEBSTAGING" returned
message "[MySQL][ODBC 5.3(w) Driver]Optional feature not supported".
Msg 7391, Level 16, State 2, Procedure
trg_DeliveryPartMap_Mysql_Stockupdate, Line 32 The operation could not
be performed because OLE DB provider "MSDASQL" for linked server
"WEBSTAGING" was unable to begin a distributed transaction.
moreover select Query works fine in sql server trigger.
But when I run on Linnked server it works fine
UPDATE OpenQuery(WEBSTAGING, 'SELECT inventory, id, originalId FROM product
WHERE originalId=Xxx') SET inventory = 13
I solved it by calling stored procedure from local server of Linked Server (MySQL Server)
without using OpenQuery I used Exec (Linked server stored procedure)
and it worked
Thanks

SQL Server 2016 Fails Cryptically (Error #7303) on Link to MySQL, But Access 2016 Succeeds with Same System DSN

I am going around in crop circles, trying to set up a linked server (from SQL Server 2016 to MySQL).
Here is the basic procedure that I used: Create a Linked Server to MySQL from SQL Server. Upon clicking OK to create the new linked server, I received the following SSMS 2016 spasm, Error #7303:
The linked server has been created but failed a connection test. Do you want to keep the linked server?
Additional information:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQL".
OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified". (Microsoft SQL Server, Error: 7303)
I tried variations that included a Provider String and Catalog (same error):
I have tried the latest MySQL ODBC ANSI/Unicode drivers (5.03.07.00), set up via System DSNs in both the 32- and 64-bit versions of the ODBC Data Source Administrator.
Now, I suspect that something screwy is going on with MS SQL Server and/or its OLE-DB Provider (MSDASQL), because:
All tests of the System DSNs within the ODBC Data Source
Administrator are successful.
Crippled Access 2016 is able to link (via the aforementioned Unicode System
DSN) to MySQL just fine, with minimal effort, listing all databases
and tables.
What is the magic that SQL Server 2016 needs to make the linked-server dialog not result in the above error?
Two things --
Product Name should be MSDASQL.
Leave Provider String and Catalog blank (these are typically taken care of by your DSN definition).
That should do it...

MySql Linked Server from MSSQL server? [duplicate]

I'm trying to migrate a table from MySql to MSSQL using openquery but I keep getting the following error message:
OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "Requested conversion is not supported.".
Msg 7341, Level 16, State 2, Line 1
Cannot get the current row value of column "[MSDASQL].description" from OLE DB provider "MSDASQL" for linked server "MYSQL".
The SQL query I'm trying to run:
insert into dbo.tickets (id, description, createdAt)
select * from openquery(MYSQL, 'select * from mydb.tickets')
With openquery I have already copied a couple tables but this one tricks me.
On both side of databases the description field is varchar(8000). In MySql there is no row where description is null and the longest description is only 5031 characters.
I tried creating a new view in MySql with the same data structure but got the same error.
I can't determine which row has an invalid description field because the table contains more than 65000 rows.
I also tried dumping the data into an SQL file but I got OutOfMemoryException in Management Studio. The dumped sql file itself is about 60 MB.
Any suggestions or other ways of migrating this data?
Thanks in advance!
In my testing, I found that adding CAST(field as char(4000)) also solved the problem.
I created the following in a MySQL 5.1 database:
create table tmp_patrick (summary_text varchar(4096));
insert into tmp_patrick values ('foo');
When I executed the following on SQL Server 2008 R2 SP1 (10.50.2500), using MySQL ODBC driver 64-bit, either version 5.1 or 5.2w:
select * from openquery(MYSQL, 'select summary_text from scratch.tmp_patrick')
it generates the error:
OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "Requested conversion is not supported.".
Msg 7341, Level 16, State 2, Line 1
Cannot get the current row value of column "[MSDASQL].summary_text" from OLE DB provider "MSDASQL" for linked server "MYSQL".
but if I add CAST:
select * from openquery(MYSQL, 'select CAST(summary_text as char(4000)) from scratch.tmp_patrick')
then it works. Casting to char(4001) will fail.
It's not clear to me where the 4000 character limit comes from.
I managed to fix this issue by changing the datatype to TEXT at both MySql and MSSQL side.

Inserting row from MSSQL to MySQL

I have set up a linked server with the MSDASQL provider in MSSQL to connect to a MySQL instance. I have installed and configured the MySQL ODBC 5.1 Driver connector. Everything seems to work fine to query data from the MySQL instance, but inserting or updating any data is not working. The following command:
INSERT OPENQUERY(MYSQL, 'SELECT id FROM test')
values (1)
intended on inserting a simple value of 1 returns the error:
OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "[MySQL][ODBC 5.1 Driver][mysqld-5.5.21]Commands out of sync; you can't run this command now".
Msg 7343, Level 16, State 2, Line 1 The OLE DB provider "MSDASQL" for linked server "MYSQL" could not INSERT INTO table "[MSDASQL]".
I have also attempted to open an editable results pane for the MySql test table and insert data that way, I receive the following error:
The operation could not be performed because OLE DB provider "MSDASQL" for linked server "MYSQL" was unable to begin a distributed transaction.
OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "[MySQL][ODBC 5.1 Driver]Optional feature not supported".
Does anyone have some insight or experience on how to solve this problem?

SQL Server 2008 linked MySQL server slow

Running MSSQL Server 2008 Standard SP 2 64-bit on Win2K8. I have installed on this server the 64-bit MySQL ODBC driver version 5.1.8 from 10/28/2010. I have configured a DSN linking to a MySQL server 5.1 running on a Mac apple-darwin9.8.0 server (don't ask me, I inherited this). I have successfully created a linked server via MDSASQL to a specific MySQL database.
From the SQL Server box I can run simple queries of the nature
SELECT * FROM mysql_table WHERE id = 1;
However, it is painfully slow. A query as above takes 19 minutes and 52 seconds to execute; the same query takes 0.04 seconds when executed locally.
Further, I attempted to execute a simple update of the nature
UPDATE mysql_table SET field = 0 WHERE id = 1;
This ran for 2 hours before returning the following error:
OLE DB provider "MSDASQL" for linked server "LINKED_MYSQL" returned message "Out of memory.".
Msg 7399, Level 16, State 1, Line 3
The OLE DB provider "MSDASQL" for linked server "LINKED_MYSQL" reported an error. The provider ran out of memory.
Msg 7330, Level 16, State 2, Line 3
Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LINKED_MYSQL".
This comes on the heels of several failed jobs involving updates to the same table, all of which fail approximately two hours after they commence.
I have checked the permissions on the mysql and the user specified in the DSN has the appropriate permissions (well, all permissions) in mysql.user.
I would be most appreciative if anyone could give me any avenues to investigate to get this working.
Avoid joins to linked server tables and have a look at dynamic openqueries
And refer to this question that posted ealier.
Linked Server Performance and options