Solved

Insert into the Linked Database

Posted on 2004-09-28
8
296 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
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…

624 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