Transfering data to mysql from sql server using linked servers - mysql

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

Related

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

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

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.

SQL Server inserts within a trigger to a linked MySQL server not working

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.