Solved

Insert into the Linked Database

Posted on 2004-09-28
8
283 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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

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!

Question has a verified solution.

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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…
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…

685 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