Cannot create trigger on linked server in SQL Server - sql-server

I have one local database in SQL Server and one Oracle database as an linked server in SQL Server. I want to create a trigger on the linked server (Oracle database table) which will insert data into SQL Server table. This is what I have tried
CREATE TRIGGER TrgItemInsert
ON ORACLEDB..SYSTEM.ITEM
AFTER INSERT
AS
BEGIN
PRINT 'Something Happened to Table ITEM'
END
but I get the following error:
The object name 'ORACLEDB..SYSTEM.ITEM' contains more than the maximum number of prefixes. The maximum is 2.
Is this possible?
Is there any work around to achieve this task?
Connection to the linked server is working and I can query the data in the linked server using 'SELECT' statements.
Thanks in advance.

Related

Query from SQL Server tables in Oracle using ODI

I have a database in Oracle and a database in SQL Server.
I want to write a query in Oracle and I need to use one of SQL Serever table in it.
Before I used database link but now I must to do this with ODI (Oracle Data Integrator).
The way I used before:
CREATE PUBLIC DATABASE LINK "DBLINK"
CONNECT TO "MatrisApp" IDENTIFIED BY VALUES ':1'
USING 'dg4msql';
INSERT
INTO everyday_deposit_temp ***/*this is a table in oracle*/***
(
"DEP_ID",
"REF_DEPOSIT_TYPE",
"REF_DEPOSIT_SUB_TYPE",
"LEDGER_CODE_SELF"
)
SELECT "DEP_ID",
"REF_DEPOSIT_TYPE",
"REF_DEPOSIT_SUB_TYPE",
"LEDGER_CODE_SELF"
FROM dbo.vw_deposit_changed#dblink
Please help me with this
The most common way to get data from MS SQL Server to Oracle through ODI is to use LKM MSSQL to ORACLE (BCP SQLLDR).
Now if you really want to use a dblink, I would try this approach:
Duplicate a Oracle IKM you want to use
In the definition tab, check the Multi-Connections checkbox and set Microsoft SQL Server for the Source Technology.
In the Options tab, add a new option DBLINK_NAME with Value type.
In the Tasks tab, find the task responsible of the insert and edit the target command to add this after the table name : #<%=odiRef.getOption("DBLINK_NAME")%>
Create a mapping using the new IKM. In the Physical tab, click on the target table and add the dblink name in the Option.

SQL Server select from linked server throw error if user has "deny view definition"

I have users with datareader permission on my sql, the problem is that i noticed that the users are doing "fishing" query a lot (they don't know what exactly should be querying to get what thy need).
This is a production SQL and we started to have deadlock because of those users.
Trying to don't break their process i applied "deny view definition to [user]" so they cannot see the list of tables, view, stored procedure, so no more "fishing"
This was a great solution, it works perfect if you connect directly to the SQL Server, you can run queries (select) but you cannot see the list of tables.
However many users are using those account to connect to our SQL using linked server, and when the run a query using the linked server they are getting error:
SELECT TOP 100 *
FROM [SERVERSQL].[DATABASE].dbo.[TABLE]
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "SERVERSQL" does not contain the table ""[DATABASE]"."dbo"."[TABLE]"". The table either does not exist or the current user does not have permissions on that table.
Using SQL Server version 2014 (v12.0.2000.8) and 2016 (v13.0.5492.2).
What is the correct way to hide tables, view, stored procedures, etc but allow select and make it work on linked server?
Thanks
Linked server from one SQL Server to Another:
Linked server name is: PLWNSAVSQL02D which is SQL Server
This sql to linked server works:
select count(*) from [PLWNSAVSQL02D].[SFI_WMS].dbo.[TCOMPANYPALLETMESSAGES];

How to copy data from a view of one server into the database table of another server in a SQL server database?

how can i copy data from a view of one server into the database table of another server in a SQL server database without using linked servers method.
I tried using the code:
SELECT [LogEntryID]
,[TimeStamp]
Into [server-2].[database1].[dbo].[table1]
FROM [server-1].[database1].[dbo].[view_1]
I recieve the error " The object name 'server-2.database1.dbo.table1' contains more than the maximum number of prefixes. The maximum is 2.
The copying statement i am using in a groovy code. But for first i am trying it in a query if it works.
You can use opendatasource instead of linked server
insert DestinationTable
select * from opendatasource('SQLOLEDB', 'Server=SourceServer;User Id=Username;Password=Password;').SourceDb.Schema.SourceTable;
OPENDATASOURCE

SQL Server Trigger on a Linked Server for reporting services

I have and SQL server with a report table that is linked to an SQL database on a separate server. The linked server is maintained by a 3rd party vendor so I'd rather not add triggers... I was hoping to run a report based on a value being inserted on a linked table. Tried the following:
CREATE TRIGGER [dbo].[RunReport] ON [linkedServer].[database].[dbo].
[CustomerComments]
FOR INSERT
AS
exec [ReportServer].dbo.AddEvent #EventType='TimedSubscription',
#EventData='xxxxx'
I get the error "contains more than the maximum number of prefixes. The maximum is 2." Anyway to trigger my report without altering the linked database. I also created a view of the linked table that didn't work either.
Thanks,
Leaving aside the idea, you can create the trigger on linked server this way:
exec [linkedServer].[database].sys.sp_executesql N'CREATE TRIGGER [dbo].[RunReport] ON [dbo].
[CustomerComments]
FOR INSERT
AS
exec [ReportServer].dbo.AddEvent #EventType='TimedSubscription',
#EventData='xxxxx'

Load Data From Linked Server to Another Linked Server

I have an Integration Server where I have defined linked servers of my sources (SQL Server database) and target database (Azure SQL DW). I have conditions where if the table does not exist I will use a SELECT INTO, then use an INSERT INTO when the table already exists.
My code is as follows:
SELECT *
INTO [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl]
FROM [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl];
INSERT INTO [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl]
SELECT *
FROM [tgt_svr].[tgt_db].[tgt_sch].[tgt_tbl];
However when I execute I get this error
... contains more than the maximum number of prefixes. The maximum is 2.
Appreciate any help how to resolve this and achieve my result to have this processing server extract from source server and load to target server.
Thank you!

Resources