Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Insert into the Linked Database

I have an Sql Server database. I link this database to oracle database (I configure that using Enterprise Manager). Now, I want to write a trigger that insert any new inserted tuple in the oracle. I tried the following:

Create TRIGGER x ON [dbp].[MYTable]
FOR INSERT
AS
INSERT INTO [Linke_Server].[DatabaseName].[Table] Values(col1.inserted,col2.inserted)

but it didn't work.. Some one tell me that I should use OpenQuery, but i don't know how to do that as insertion. Any idea??
0
mth2020
Asked:
mth2020
  • 4
  • 4
1 Solution
 
BillAn1Commented:
the syntax for the insert statement is

Create TRIGGER x ON [dbp].[MYTable]
FOR INSERT
AS
INSERT INTO [Linke_Server].[DatabaseName].[Table]
SELECT col1, col2
FROM inserted
0
 
mth2020Author Commented:
it didn't work
even though I tried simple insert


Create TRIGGER x ON [dbp].[MYTable]
FOR INSERT
AS
INSERT INTO [Linke_Server].[DatabaseName].[Table]
Values('sss')

it didn't work
0
 
BillAn1Commented:
what happened? did you get an error? did your server explode? ...
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
mth2020Author Commented:
of course the server didn't explode otherwise you will not see me here.
The error which I get is
[Microsoft][ODBC SQL Server Driver][OLE/DB provide returned message: NEw transection cannot enlist in the specified transection coordinator]

[Microsoft][ODBC SQL Server Driver][Sql Server] THe operation could not be performed because the OLE DB provider 'OraOLEDB' was unable to begin  a distributed transection.
0
 
BillAn1Commented:
can you run the insert statement outside a trigger? e.g. in QA can you run
INSERT INTO [Linke_Server].[DatabaseName].[Table]
Values('sss')

this will determine if it is DTC or not that is the problem. Within triggers, code always runs as distributed transaction, even if it does not join to other tables etc.


here's some tips on how to troubleshoot DTC, and how to set up Oracle linked servers correctly

http://support.microsoft.com/default.aspx?kbid=306212
http://support.microsoft.com/default.aspx?scid=kb;EN-US;280106
http://support.microsoft.com/default.aspx?scid=kb;en-us;329332
0
 
mth2020Author Commented:
In QA when I tried

select * from
OpenQuery(Link,'select * from Link.scott.NameOFTheTable'

I got
OLE/DB Provider Returned: ORA-00933
0
 
BillAn1Commented:
"link" I presume is the name in SQLServer you have given to refer to your Oracle server. This is not something you pass through to Oracle,
the query you pass to Oracle, if you are using OpenQuery would be something like 'select * from scott.NameOfTable'
i.e.


select * from
OpenQuery(Link,'select * from scott.NameOFTheTable')

you can acheive the same result with

select * from link.scott.NameOfTable
0
 
mth2020Author Commented:
I still has the problem. with the Query Analyizer the following Query work fine:

INSERT INTO LINK.SCOTT.X Values('Hello')

The effect is reflected at oracle database. The problem is when I write this in the trigger,

CREATE TRIGGER MYTrigger ON [dpo].[SQLTest]
FOR INSERT, UPDATE, DELETE
AS
INSERT INTO LINK.SCOTT.X Values('Hello')

Now when I try to insert new tuple in SQLTest table, I got the following error:

[Microsoft][ODBC SQL Server Driver][OLE/DB provide returned message: NEw transection cannot enlist in the specified transection coordinator]
[Microsoft][ODBC SQL Server Driver][Sql Server] THe operation could not be performed because the OLE DB provider 'OraOLEDB' was unable to begin  a distributed transection.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now