Update MySQl Linked server from sql server trigger - mysql

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

Related

Transfering data to mysql from sql server using linked servers

My problem is that i'm trying to transfer some data to mysql from my sql server and it returns this error
OLE DB provider "MSDASQL" for linked server "SRV" returned message "[MySQL][ODBC 8.0(a) Driver]Optional feature not supported". Msg 7391,
Level 16, State 2, Procedure exportbds, Line 10 [Batch Start Line 2]
The operation could not be performed because OLE DB provider "MSDASQL"
for linked server "SRV" was unable to begin a distributed
transaction.
I have established a linked server between the last two (connection successful) and used the cmd OPENQUERY ([MyLinkedserver], 'query') inside a stored procedure and called by a trigger after insert, so that whenever i insert my data into my table it transfers directly to mysql. here below i'll be sharing with you my code :
My trigger after insert
ALTER TRIGGER [dbo].[exportbds] on [dbvlms].[dbo].[so_bs_creation_duplicata]
AFTER insert
as
exec [dbo].[exportbondesortie]
TRUNCATE TABLE [dbo].[so_bs_creation_duplicata]
My Stored procedure
ALTER PROCEDURE [dbo].[exportbondesortie]
AS
BEGIN
INSERT INTO OPENQUERY (SRV, 'SELECT id, id_bs FROM mapping_db.so_bs_creation')
SELECT * FROM OPENQUERY (EDIPRODB2BI01, 'SELECT id, id_bs FROM dbo.so_bs_creation_duplicata')
END

MS SQL Server and MySQL through Linked Server

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.

Error when executing Insert Trigger with distributed Querys (OpenQuery)

My MSSQL trigger:
ALTER TRIGGER [dbo].[ioTrigger_dbo_vsolv_mst_tproddtchng]
ON [dbo].[vsolv_mst_tproddtchng]
for INSERT
AS
BEGIN
SET NOCOUNT ON;
INSERT OPENQUERY (LINKED,'SELECT proddtchng_product_gid,
proddtchng_mrp,
proddtchng_tndpwtax,
proddtchng_tndpwotax,
proddtchng_kldpwtax,
proddtchng_kldpwotax,
proddtchng_costprice,
proddtchng_website,
proddtchng_purpose,
proddtchng_weight,
proddtchng_suitable,
proddtchng_workingrange,
proddtchng_cutoff,
proddtchng_timedelay,
proddtchng_description,
proddtchng_validfrom,
proddtchng_validto,
proddtchng_createby,
proddtchng_createdate,
proddtchng_isactive,
proddtchng_isremoved
from vsolv_line_tn.vsolv_mst_tproddtchng')
SELECT
proddtchng_product_gid,
proddtchng_mrp,
proddtchng_tndpwtax,
proddtchng_tndpwotax,
proddtchng_kldpwtax,
proddtchng_kldpwotax,
proddtchng_costprice,
proddtchng_website,
proddtchng_purpose,
proddtchng_weight,
proddtchng_suitable,
proddtchng_workingrange,
proddtchng_cutoff,
proddtchng_timedelay,
proddtchng_description,
proddtchng_validfrom,
proddtchng_validto,
proddtchng_createby,
proddtchng_createdate,
proddtchng_isactive,
proddtchng_isremoved
FROM
inserted;
END
When I am executing the above trigger I am getting the following error:
OLE DB provider "MSDASQL" for linked server "LINKED" returned message "[MySQL][ODBC 5.3(a) Driver]Optional feature not supported".
Msg 7391, Level 16, State 2, Procedure ioTrigger_dbo_vsolv_mst_tproddtchng, Line 8
The operation could not be performed because OLE DB provider "MSDASQL" for linked server "LINKED" was unable to begin a distributed transaction.
I have created a Linked server to Mysql from Sqlserver2008, I have already configured the DTC and its status is running, automatic, please help me how should I overcome the above error.
Its your Distrubution tranasaction property which breaks while creating procs/triggers into Linked servers, especially with Non-MSSQL connections
1) right click on Linked server
2) Select Properties and enable this- Set Property to False
Run Proc:
EXEC master.dbo.sp_serveroption #server=N'SVRLINK',
#optname=N'remote proc transaction promotion', #optvalue=N'false
Did you tried
SET XACT_ABORT OFF
The SQL-Server is trying to start a distributed transaction for a possible rollback on the linked server (myssql). There are some settings in the linked-server options to enable distributed transactions.
Maybe this will help:
Distributed Transaction on Linked Server between sql server and mysql

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