Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert into the Linked Database

Posted on 2004-09-28
8
Medium Priority
?
304 Views
Last Modified: 2006-11-17
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
Comment
Question by:mth2020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:BillAn1
ID: 12168290
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
 

Author Comment

by:mth2020
ID: 12168390
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
 
LVL 17

Expert Comment

by:BillAn1
ID: 12168408
what happened? did you get an error? did your server explode? ...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mth2020
ID: 12168832
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
 
LVL 17

Expert Comment

by:BillAn1
ID: 12170114
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
 

Author Comment

by:mth2020
ID: 12178034
In QA when I tried

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

I got
OLE/DB Provider Returned: ORA-00933
0
 
LVL 17

Accepted Solution

by:
BillAn1 earned 1000 total points
ID: 12178240
"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
 

Author Comment

by:mth2020
ID: 12206555
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question