Solved

Insert into the Linked Database

Posted on 2004-09-28
8
249 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
Comment Utility
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
Comment Utility
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
Comment Utility
what happened? did you get an error? did your server explode? ...
0
 

Author Comment

by:mth2020
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 17

Expert Comment

by:BillAn1
Comment Utility
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
Comment Utility
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
Comment Utility
"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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now