question

Ramu avatar image
Ramu asked

Trigger for insert,update,delete to copy a table data from one databse to another present in different server location

Hii to all I have a requirement that,i have two tables (i)mainlog,present in sqlserver(ii)sparelog,present in MySql which is present in different server location.I need to write a trigger to copy a mainlog table data to sparelog table.when ever any DML operation is performed to mainlog table the trigger has to fire automatically and reflect the same to sparelog table present in different server location.I have already created a Linkedserver to Mysql from my local Sqlserver. I have tried by writing the following trigger and successfully copied the table data from mainlog table to sparelog table for only insert operation,and with in the same instance of sqlserver:- CREATE TRIGGER LogRecords ON mainlog FOR INSERT AS BEGIN SET NOCOUNT ON IF EXISTS(SELECT * FROM mainLog) INSERT OPENQUERY(MySQL,'SELECT * FROM sparelog') SELECT * FROM INSERTED ELSE INSERT OPENQUERY(MySQLLinkedSvr,'SELECT * FROM sparelog') SELECT * FROM INSERTED END The above trigger working only when both the tables are present in same sqlserver.Can any one help me how to rectify my above trigger so that i can perform all the Insert,Update,Delete, operation with only single Trigger when both the tables present in different server location. Also iam finding the below error when iam trying to insert,update,delete, operation on a table present in different server location(MYSQl db) ERROR:-OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "[MySQL][ODBC 5.2(a) Driver]Optional feature not supported". Msg 7391, Level 16, State 2, Procedure MYSQLLogRecords, Line 12 The operation could not be performed because OLE DB provider "MSDASQL" for linked server "MYSQL" was unable to begin a distributed transaction. Thanks Ramu
sql-server-2008mysql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
You need to first ensure that your connection to MySQL is set up correctly. Read [this post][1] over on SQL Server Central. It acts as a good reference. A possible workaround if that doesn't help [is here][2]. [1]: http://www.sqlservercentral.com/Forums/Topic340912-146-1.aspx [2]: http://forums.mysql.com/read.php?60,209856,256141#msg-256141
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ramu avatar image Ramu commented ·
Hii thanks for ur responce, I have configured all the things in the above links,still iam finding the same error,can u please guide me is there any alternative to meet my above mentioned requirement i.e all the DML operation made to the source table should reflect to destination table automatically present in different server location. Can we try with stored procedure,if yes how should i go with that to meet my requirement,provide any links for the same....thanks in advance Regards Ramu
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
I am just not acquainted sufficiently with MySQL. The key point is that you have to be able to start a distributed transaction, or you have to avoid the transaction entirely. The primary problem is MySQL. I'd suggest a different storage mechanism. SQL Server Express or Azure SQL Database maybe.
0 Likes 0 ·
Ramu avatar image Ramu commented ·
Dear fritchey,Thanks for ur valuable feedback i wil try with ur above suggessions,do u have any links please provide me... Thanks Ramu
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.