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
Related
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
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 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
I have a table say Table1 on SQL Server 2014 and MySQL both.
Table1
ID INT,Code VARCHAR(100)
I created a linked server MyLinkedServer in SQL Server using "Microsoft OLEDB Provider for ODBC".
**Linked Server **
EXEC master.dbo.sp_addlinkedserver #server = N'MyLinkedServer', #srvproduct=N'MyLinkedServer', #provider=N'MSDASQL', #datasrc=N'MyLinkedServer'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'MyLinkedServer',#useself=N'False',#locallogin=NULL,#rmtuser=N'username',#rmtpassword='########'
Linked Server Settings
EXEC master.dbo.sp_serveroption #server=N'MyLinkedServer', #optname=N'data access', #optvalue=N'true'
EXEC master.dbo.sp_serveroption #server=N'MyLinkedServer', #optname=N'use remote collation', #optvalue=N'true'
EXEC master.dbo.sp_serveroption #server=N'MyLinkedServer', #optname=N'remote proc transaction promotion', #optvalue=N'true'
The linked server is created successfully and I am able to query Mysql Table in SQL Server.
Query
When I run
INSERT INTO MyLinkedServer...Table1(ID,Code) SELECT 1,'Code1'
The record is inserted. However when I start a transaction and run the INSERT, I get an error:
BEGIN TRAN
INSERT INTO MyLinkedServer...Table1(ID,Code) SELECT 1,'Code1'
COMMIT
Error:
OLE DB provider "MSDASQL" for linked server "MyLinkedServer" returned message "[MySQL][ODBC 5.3(a) Driver]Optional feature not supported".
Msg 7391, Level 16, State 2, Line 8
The operation could not be performed because OLE DB provider "MSDASQL" for linked server "MyLinkedServer" was unable to begin a distributed transaction.
What I have tried so far.
Enable XA Transactions in MSDTC
Enabled following setting in Linked Server Provider
Nested queries
Level zero only
Allow inprocess
Supports ‘Like’ Operator
I checked the following links and their suggestions however the error persists:
Distributed transactions between MySQL and MSSQL
SQL-Server and MySQL interoperability?
SQL Server and MySQL Syncing
EDIT
Additional Details:
MySQL is using InnoDB storage engine on Ubuntu machine.
I have already configured the ODBC connector and used it to configure a ODBC System Data Source which is used in the Linked Server
Theoretically this should work.
I would suggest different steps to sort this out:
Have you checked you MySql storage engine yet? It looks only InnoDB storage engine support distribute transaction per MySql document: https://dev.mysql.com/doc/refman/5.7/en/xa.html
See if you can switch to use MySQL Connectors setup connection to connect to MySql in SQL Server instead of OLEDB provider, which state by MySql document above that support distribute transaction.
If still not working, it might be the MSDTC service itself has some problem, see if you can isolate that like get a SQL Server instance running on the MySql server box(if you are using Windows MySql), or try install Windows MySql on the Sql Server box to get distribute transaction working between two MySql. Which would be able to point you to the actual problem.
EDIT:
Unfortunately it looks that you proved this not working, I've a closer look at the MySql document and sorry it looks that I wasn't reading it thoroughly, it says:
Currently, among the MySQL Connectors, MySQL Connector/J 5.0.0 and higher supports XA directly
And by some other Googling I found this: https://bugs.mysql.com/bug.php?id=37283, people report this bug many years ago and they marked this as a won't fix.
Some one suggested something here: https://social.msdn.microsoft.com/Forums/en-US/fc07937d-8b42-43da-8c75-3a4966ab95f9/xa-msdtc?forum=windowstransactionsprogramming, which is to implement your own XA-Compliant Resource Managers to be used by your application (https://msdn.microsoft.com/en-us/library/ms684317.aspx)
As on SQL 2014, you could have configured the linked server not to enlist in a distributed transaction. Although you could try adding "Enlist=false" in the #provstr argument to sp_addlinkedserver
I'm trying to test inserts to a linked MySQL server using triggers, but am having a few problems.
System-
Windows 2003 Server running
- SQL Server 2008 R2 Developer Edition
- MySQL 5.5.15.0 Server
- MySQL ODBC 5.1 driver
I followed the instructions in this post - http://www.sqlservercentral.com/Forums/Topic340912-146-1.aspx to link the MySQL server to SQL server
I can SELECT and INSERT rows in the linked server using the query window in SSMS.
The problem arises when I try to do an INSERT to the linked server in a trigger
Trigger
USE [Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[update_trig] on [dbo.test]
for insert
as
SET XACT_ABORT ON
INSERT INTO OPENQUERY(MYSQL, 'select data from roh.test') values ('testing trigger')
When a row is inserted into the SQL server the following error occurs
Msg 7391, Level 16, State 2, Procedure update_trig, Line 7
The operation could not be performed because the OLE DB provider "MSDASQL" for linked server "MYSQL" was unable to begin a distributed transaction.
After doing a bit of googling someone suggested adding a COMMIT statement to the trigger after SET XACT_ABORT ON, so the last part of the trigger looks like
SET XACT_ABORT ON
COMMIT
INSERT INTO OPENQUERY(MYSQL, 'select data from roh.test') values ('testing trigger')
This does do the insert in the linked MySQL server but gives the error -
Msg 3609, Level 16, State 1, Line 1
The transaction ended in the trigger. The batch has been aborted.
Someone also suggested doing the insert in a stored procedure and calling this from the trigger, but this gives the same errors.
Am I missing something, or is this not possible? Any suggestions would be appreciated.