Linked Server Insode Triggers Problems?
Aug 8, 2007
Dear all
I am trying to use linked server objects inside a trigger and have some major problems.
Just to explain what i am trying to achieve:
My server A is SQL 2000. When ever a row is added to a table on server A i would like to send some of the inserted values to server B which is a physically different computer and has SQL 2005.
To do that i created linked server object on the SQL 2000 side.
To test the linked server object i go:
Select * ServerB.Database.dbo.Table
This works perfectly and i get the results. I then test the same inside a stored procedure but i do some parameterised queries.
Select id from ServerB.Database.dbo.Table where id=@myId
This also works perfectly inside the stored procedure.
BUT NOW IT COMES THE FUN PART.
As soon as i place this inside the trigger it just doesnt work. My trigger has nothing else pretty much except for that. Here is a sample:
BEGIN
SET NOCOUNT ON
SET xact_abort ON
DECLARE @myValue nvarchar(50)
SET @myValue = '6357'
SELECT * from ServerB.Database.dbo.Table
Where id = @myValue
END
It just gives me a timeout error. But what is even worse is that after this the whole database is crashed and i have to restart the database service to make it work.
I checked both servers and they have the service DTS for the distributed transaction on. No proxies, no firewals. Also i checked the servers configuration and they have RPC,RPC OUT and Data Access enabled.
I have tried everything over the last week and nothing has worked for me.
Any advice would be much much apreciated.
Sincerely
Dan
View 5 Replies
ADVERTISEMENT
Nov 10, 2014
I have a system where people can apply for registration and also a registration fee is involved. The screen where the application is captured has a couple of inserts into different tables. Each of these tables have triggers on them to transfer data to a linked server and they work fine. Today I just added another trigger on a different table but also part of this same save process. Now I am getting the following error:
Microsoft OLE DB Provider for SQL Server error '80004005'
The statement has been terminated.
/orisys.int.za/applicants/ApplicantInsert.asp, line 111
I do not know this error and think it might be time-out.
View 9 Replies
View Related
Jun 17, 2004
I've been working on this for a couple of days now, trying different scenarious.
Problem:
I created a 'FOR INSERT' trigger on server1.dbs1.owner.table1 to collect information and insert to a linked server server2.dbs2.owner.table2. When I run with the trigger active, SQL Analyzer just hangs in there "Executing Query Batch ..." indefinately. When I don't create the trigger, but run all parts manually from SQL Analyzer, it works fine.
What did I try:
1. create a 'FOR INSERT' trigger on server1.dbs1.owner.table1 to insert into server1.dbs1.owner.table2. This worked fine.
2. create a stored proc to execute within the trigger on server1.dbs1.owner.table1 to insert to server2.dbs2.owner.table2. This just hangs in there "Executing Query Batch ..." indefinately.
What now?
I have a suspicion that something is not working correctly with the triggers and the linked servers. Has anyone encountered a similar problem and what did you do to overcome this? I greatly appreciate all responses and suggestions. Thanks all.
View 1 Replies
View Related
Oct 21, 2004
I have two servers one on SQL Server 2000 one on SQL Server 7
I have setup the two servers so that they are linked and have added appropriate logins.
How it works is a record is inserted into a database on SQL 2000 which has a trigger on it that send the record to a stored procedure on the SQL 7 server, from there this places the record into a table, which calls a trigger. Now this all works fine when I use the query analyser however when I don't use it, the record does not get inserted anywhere. Now I have stepped through it and it works up until the last trigger, if I remove that everything works fine. However the code in this trigger works fine, as when I use the quuery analyser everything works just as it should.
Does anyone have any suggestions as to how I can get this to work?
Thanks :-)
View 2 Replies
View Related
Apr 19, 2004
Can i write triggers beteen the linked servers.Here is the whole scenario. I have 3 servers. Server aaaa and server bbbb has replication in between them.Server aaaa is a publisher and server bbbb is the suscriber. I have another server cccc.So If i make any change on a table xxxx should effect the tablee xxxx on server aaaa and bbbb.So i am writing a trigger(for insert,update and delete on the table) xxxx on the server ccccc.So that trigger should take care of any DML(insert,update and delete) happend on table xxxx on server cccc and should effect on server aaaa and then the replication should take care of server bbbb.This want i am planning right now?Is it a good practice to implement in such a requirement?
Please help me.
Thanks.
View 5 Replies
View Related
Jul 20, 2005
I have two SQL Server 2000 machines (server_A and server_B). I'veused sp_addlinkedserver to link them both, the link seems to behavefine. I can execute remote queries and do all types of neat thingsfrom one while logged onto the other.I'm working on a project to keep the data in the two systemssynchronized, so I'm using triggers on both sides to update eachother. For testing, I've created a simple, one-column table on bothservers, and also created a trigger on both tables. Consider thefollowing trigger code on server_A:CREATE TRIGGER myTriggerON myTableFOR INSERTASSET XACT_ABORT ONSET NOCOUNT ONINSERT INTO server_B.myDB.dbo.myTable SELECT * FROM insertedGOAnd also the following trigger code on server_B:CREATE TRIGGER myTriggerON myTableFOR INSERTASSET XACT_ABORT ONSET NOCOUNT ONINSERT INTO server_A.myDB.dbo.myTable SELECT * FROM insertedGOBefore you start screaming about the recursive relationship betweenthese triggers, I'm well aware of that issue, so I'm wrapping thetrigger logic with a login ID test. The servers are linked using aspecial login account, I'll call it 'trigger_bypass_login', so thetriggers look like this:CREATE TRIGGER myTriggerON myTableFOR INSERTASSET XACT_ABORT ONSET NOCOUNT ONIF SUSER_SNAME() <> 'trigger_bypass_login'INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM insertedGOAlthough this logically works fine, there seems to be a compile issue,because I'm running into the error:The operation could not be performed because the OLE DB provider'SQLOLEDB' was unable to begin a distributed transaction.[OLE/DB provider returned message: New transaction cannot enlist inthe specified transaction coordinator. ]OLE DB error trace [OLE/DB Provider 'SQLOLEDB'ITransactionJoin::JoinTransaction returned 0x8004d00a].What is strange is that I CONTINUE TO GET THE ERROR if I change thetrigger code to the following:CREATE TRIGGER myTriggerON myTableFOR INSERTASSET XACT_ABORT ONSET NOCOUNT ONIF 1=0INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM insertedGOSo obviously, it has nothing to do with the actual inserting that theINSERT performs, but rather the fact that the trigger INSERTreferences the linked server/table.So, I moved the INSERT statement to a stored procedure, and it worksand I no longer get the error:CREATE TRIGGER myTriggerON myTableFOR INSERTASSET XACT_ABORT ONSET NOCOUNT ONIF SUSER_SNAME() <> 'trigger_bypass_login'EXEC myStoredProcedureGOIt works.. BUT, the stored procedure does not have access to the SQLServer 'inserted' trigger table. I've tried usingDECLARE CURSOR myCursor GLOBAL FOR SELECT * FROM insertedand then letting the stored procedure reference the cursor, but then Ihave to deal with the cursor data on a column-level basis, which isnot an option in this project because there are 100's of tables withmany columns, which might change over time.So it is of extreme importance that I use INSERT INTO ... SELECT tomove the row data in a generic fashion.I hope I have provided enough, yet not too much, information.I would really appreciate any suggestions anyone might have as to howI might handle this situation. Thanks.Hank
View 4 Replies
View Related
Mar 25, 2002
Hi ,
On my Desktop i registered Production Server in Enterprise Manager
on that Server if i go to SecurityLinked Servers
There is another Server is already mapped, when i am trying to see the Tables under that one of the
Linked Server i am getting the Error message saying that
"Error 17 SQL Server does not exist or access denied"
if i went to Production Server location and if i try to see the tables i am able to see properly, no problems
why i am not able to see from my Desk top
i am using the sa user while mapping the Production Server on my DESKTOP using (ENTERPRISE MANAGER)
And i check the Client Network Utility in the Alias using Named Pipe only, i changed to TCP/IP still same problem
What might the Problem how can i see the Tables in Linked Server from my DESKTOP
Thanks
View 5 Replies
View Related
Apr 24, 2015
I am using Linked Server in SQL Server 2008R2 connecting to a couple of Linked Servers.
I was able to connect Linked Servers, but I cannot point to a specific database in a Linked Server, also, I cannot rename Linked Server's name.
How to point the linked server to a specific database? How to rename the Linked Server?
The following is the code that I am using right now:
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver
   @server = N'Machine123Instance456',
   @srvproduct=N'SQL Server' ;
GO
EXEC sp_addlinkedsrvlogin 'Machine123Instance456', 'false', NULL, 'username', 'password'Â Â
View 6 Replies
View Related
Jul 18, 2006
Is there a way to bypass the syntax checking when adding a stored procedure via a script?
I have a script that has a LINKed server reference (see below) .
INSERT
INTO ACTDMSLINKED.ACTDMS.DBO.COILS ..etc.
ACTDMSLINKED does not exist at the time I need to add the stored procedure that references it.
PLEASE to not tell me to add the LINK and then run the script. This is not an option in this scenerio.
Thanks,
Terry
View 4 Replies
View Related
May 12, 2008
This isn€™t an problem as such, it€™s more of a debate.
If a table needs a number of update triggers which do differing tasks, should these triggers be separated out or encapsulated into one all encompassing trigger. Speaking in terms of performance, it doesn€™t make much of an improvement doing either depending upon the tasks performed. I was wondering in terms of maintenance and best practice etc. My view is that if the triggers do totally differing tasks they should be a trigger each on their own.
www.handleysonline.com
View 12 Replies
View Related
Oct 3, 2006
Hi Guys,I have a website that has a log in box, when a user logs in it automatically inserts a 1 in my users table and a little icon changes color on the web page to indicate that a person is signed in, my problem is that sometimes my users don't log off using the signout button which then puts a zero back in my table and a different coloured icon is shown. I cant seem to force them to use this button so I being new to sql server wondered if I could use a trigger to set the field to 0 after say half an hour.I also have a table that has various projects in it and they each have a field that has an estimated end date, I wondered if there was some sort of trigger I could use to fire off an email when the todays date passes that end date to notify evryone it was overdue. If this can be done please could you provide me with an example, Many thanks
View 3 Replies
View Related
Oct 18, 2001
I need help writing a delete trigger. The table that I want to audit is [dbo].[MCMESSAGE]. When there is a delete on this table I want to write the deleted row to an audit table called [dbo].[AUDIT_MCMESSAGE]. The name of my trigger is [DEL_MCMESSAGE_TR].
This is what I have so far :
CREATE TRIGGER [DEL_MCMESSAGE_TR]
ON [dbo].[MCMESSAGE]
FOR DELETE AS
INSERT [dbo].[AUDIT_MCMESSAGE]
(MessageID, ReplyToID, Sender, Subject, CreateDate,
ExpirationDate, Reply, Body, ReadReceipt, Priority, Association,
AppID)
SELECT
MessageID, ReplyToID, Sender, Subject, CreateDate,
ExpirationDate, Reply, Body, ReadReceipt, Priority, Association, AppID
FROM deleted
When I test this I delete a record from [dbo].[MCMESSAGE] I get this Error :
"[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated."
Could someone please hwlp me?
View 1 Replies
View Related
Jul 1, 2000
As per microsoft's documentation we can create more than 3 trigger per table in sql 7.o. I just like to know the meaning for this statement. If it's the case we can create more than one update trigger per table. Then which trigger will fire first and then how the other update triggers will perform. Can you please provide detailed explanation.
Regards,
gp
View 4 Replies
View Related
Feb 25, 1999
Hi, I know how to write a trigger on a table in which any insert into table A will fire an insert trigger... What I am tring to find out if the following is possible:
I want to have a trigger on a table A where it fires ONLY when anumber of rows are inserted NOT row by row.... for example. I am importing acouple of hundreds of rows into table A. Once the import process is done, I want to fire a trigger to count the total number of rows inserted into Table A... and insert the table Name, #of rows into Table called Tracking table...
Can anyone help me in finding solution for this...
thanks
regards
Ali
View 2 Replies
View Related
Feb 15, 2008
help sql server database triggers sample code ???
???
???
View 2 Replies
View Related
Feb 21, 2008
WHY DO WE USE TRIGGERS IN SQL SERVER2005.
WAT IS ITS IMPORTANCE.
AND SOME SAMPLES
PLEASE GIVE ME SOLUTIONS
View 2 Replies
View Related
Jan 23, 2006
Hi All,
I'm trying to make a trigger on a table. If the data changed, the trigger will fire and copy the table into another table.
Can u give me examples on Triggers for Update..
Thanks
View 1 Replies
View Related
Jul 31, 2000
Good afternoon one and all,
I am migrating a access dbase to SQL. I have two tables, the first is a buffer table that collects data from various sources, the second table is an indexed version of the first table (to eliminate duplicate records etc. etc.)
I am currently using the DTS packaage to transfer data between them, would a trigger be a better solution?
Thanks in advance for any and all help
Gurmi
View 2 Replies
View Related
Jul 31, 2000
Good afternoon one and all,
I am migrating a access dbase to SQL. I have two tables, the first is a buffer table that collects data from various sources, the second table is an indexed version of the first table (to eliminate duplicate records etc. etc.)
I am currently using the DTS packaage to transfer data between them, would a trigger be a better solution?
Thanks in advance for any and all help
Gurmi
View 1 Replies
View Related
Apr 12, 2007
Hi,
I am still learning the bells and whistles of SQL Server and was wondering if I can find out the query that caused my trigger to fire, so that I can log this in another audit table.
I have an If Update ( My_Column ) trigger set up, where once an update happens to My_Column much information from the updated row along with , Host_Name and App_Name is sent. I also want to send the exact query used to update it, any ideas?
Any comments, suggestions will be greatly appreciated.
Thanks,
Kartik
View 2 Replies
View Related
Jul 20, 2005
Hello,I am pretty much a newbie with SQL server. I have what is probably apretty stupid question. In SQL Enterprise manager, is there a way toeasily see all triggers, or, even better, all tables and thereassociated triggers? I suppose at the least in a way similar toviewing all saved functions or views.Thanks,Ryan
View 4 Replies
View Related
Mar 21, 2008
Hi,
I have 2 table that are exactly the same and want to create a trigger on table1 that will do the following:
Every time i delete from table1, the "Instead of delete Trigger" will automaticaly delete the data from table2 and not from table1.
Can anyone help me?
View 11 Replies
View Related
Feb 21, 2008
WHY DO WE USE TRIGGERS IN SQL SERVER2005.
WAT IS ITS IMPORTANCE.
AND SOME SAMPLES
PLEASE GIVE ME SOLUTIONS
View 1 Replies
View Related
Oct 15, 2007
hi all,
i had a view in my project, i am inserting a record in to that view(View contains a identity key for a column), with in stored procedure i am inserting a record i am not passing the identity key value to the insert statement. The record is getting inserted,Based on the identity key(i am getting the identity key value with Scope_Identity()) and with that value i am inserting records into another two tables.In this scenario every thing is working fine.
but now i am trying to place a trigger(instead of insert trigger) on the view, when i placed,it is not inserting record into first table,so i am not able to get the identity value of that record and process failed.
how can this achived, let me know.
View 2 Replies
View Related
May 1, 2008
Hello all.
For my first foray into this forum I have a tricky one....
We have a table in our database called tblJob with two columns:
id IDENTITITY(1,1)
jobNbr VARCHAR (5) (This would be, for example '12323')
When a new job is created (i.e. job Number 12323), the client wants a trigger on this table that creates a new table called tblJobData12323.
Does anyone know how I can accomplish this?
Thank you in advance.
PJ
PJ
View 2 Replies
View Related
Jan 19, 2007
Hello Guys!i have been working with oracle with quite a time. No i migrated to sqlserver 2000 and i want to create a trigger on a table.the trigger function has to update the Modification field to getdate()whenever a row is being updated.i tried lots of thingsif anyone can help i would appreciate a lot!Regards
View 2 Replies
View Related
Oct 28, 2007
I have searched the net for atmost two days to find the solution of this problem but we not able to get the solution. I would appritiate if any one could help me in solving this issue:
I have a Table :
EMPLOYEES :
EMPID EMPNAME MANAGERID
1 abc NULL
2 xyz 1
3 hty 2
4 loi 3
I want to write a trigger for deleting the EMPLOYEE with EMPID=1 and the trigger should delete all the employees as there is cascading among them i.e EMPID 1 is the Manager of EMPID=2 and so on..
I found a solution at: http://msdn2.microsoft.com/en-us/library/aa902684(sql.80).aspx
but the solution does not work when i try to implement it . It deletes the record for abc,xyz in the above table but rest are not deleted by the trigger.
Can anybody tell me the exact Trigger code......
View 7 Replies
View Related
Oct 5, 2007
I wanted to set up a trigger to alter me or log to a table when someone is added to a server role. The event for the trigger I wanted to use is ADD_SERVER_ROLE_MEMBER. When trying to create the trigger, I get the following information:
"ADD_SERVER_ROLE_MEMBER" does not support synchronous trigger registration.
View 6 Replies
View Related
Feb 24, 2007
Hi,
Can anybody let me know if there are ways to programatically track changes made to a SQL SERVER CE table? I am writing a db monitoring tool on SQL server CE which should track any changes made to the table.(Insert update and delete)
We could have done this using triggers on Sql Server 2005. Since triggers are not supported on SQL Server CE, are there any alternate ways to achieve this functionality?
Regards,
Ananth
View 3 Replies
View Related
Mar 10, 2008
Please help me in sorting out my Problem Providing me the solution .
My Problem is
I have a master table with Primary key on ID field (PatientID-(Patient-Table)) and it is an Identity field
And My child table has the same ID field(PatientID-(PatientDetails-Table)) and it has the relationship set
And the child table has its own Primary key of its own ID field(PatientdetailsID).
What I want is as soon as enter row of data into the master table (Patient-Table)and click save on my front end application(Which is ASP.Net web application)
I want to update Child Table’S (PatientDetails)ID field ( ie.,PaientID in the PatientDetailsTable) in the Child Table which relates the parent table ,by doing so I want to update the Primary key field (ie.,PatientDetailsID) & ForeignKey Field (PatientID)of the child table and to create row in the child table with two columns .(PatientID,&PatientDetailsID)
What I want to achieve is in my ASP.net Application as soon as I enter Master table
I want to Edit Child tables (about 15) one by one like a Wizard pages which will have The ID Field(PatientID) same in all my wizard pages .
I want to know whether I can incorporate triggers if so in which table (is it in Patient or PatientDetails) and I will be grateful If anyone gives the Script to-do so.I am also providing my two table sripts.
Sripts:CREATE TABLE [dbo].[Patient]( [PatientID] [int] IDENTITY(1,1) NOT NULL, [Date] [smalldatetime] NULL, [UserID] [int] NULL, [FirstName] [varchar](40) NOT NULL, [Surname] [varchar](30) NOT NULL, [DOB] [datetime] NULL, [Age] AS (floor(datediff(day,[DOB],getdate())/(365.25))), [Sex] [varchar](10) NULL, [Occupation] [varchar](30) NULL, [Ethinicity] [varchar](60) NULL, [HomeTel] [varchar](15) NULL, [Mobile] [varchar](15) NULL, [varchar](40) NULL, [AddressLine1] [varchar](30) NULL, [Line2] [varchar](30) NULL, [Line3] [varchar](30) NULL, [City] [varchar](20) NULL, [PostCode] [varchar](15) NULL, CONSTRAINT [PK_Patient] PRIMARY KEY CLUSTERED ( [PatientID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] GOSET ANSI_PADDING OFFGOALTER TABLE [dbo].[Patient] WITH CHECK ADD CONSTRAINT [FK_Patient_User] FOREIGN KEY([UserID])REFERENCES [dbo].[User] ([UserID])GOALTER TABLE [dbo].[Patient] CHECK CONSTRAINT [FK_Patient_User] CREATE TABLE [dbo].[PatientDetails]( [PatientID] [int] NOT NULL, [PatientDetID] [int] IDENTITY(1,1) NOT NULL, [Date] [smalldatetime] NULL, [NHSNumber] [varchar](12) NULL, [HospitalRefID] [varchar](10) NULL, [Ovaries] [varchar](15) NULL, [ReportFromGP] [image] NULL, [LMP] [datetime] NULL, [DateStopped] [datetime] NULL, [Comment] [varchar](150) NULL, CONSTRAINT [PK_PatientDetails_1] PRIMARY KEY CLUSTERED ( [PatientDetID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GOSET ANSI_PADDING OFFGOALTER TABLE [dbo].[PatientDetails] WITH CHECK ADD CONSTRAINT [FK_PatientDetails_Patient] FOREIGN KEY([PatientID])REFERENCES [dbo].[Patient] ([PatientID])GOALTER TABLE [dbo].[PatientDetails] CHECK CONSTRAINT [FK_PatientDetails_Patient]
I want to incorporate this through database level .
I am using SQL Server2005-Express
Although Iam using ASP.net C# I am new and I will not be able to do this in my front end.
Please help me wth the solution.
thanks
rameshs_2000
View 4 Replies
View Related
May 11, 2015
I am would like for a Trigger to fire after an SSIS job finishes.
My understanding is that i would use a AFTER trigger.
How my UPDATE and INSERT INTO would fire and only affect the new rows.
SET ARITHABORT OFF
SET ANSI_WARNINGS OFF
UPDATE [GDev].[dbo].[tblCIDetailsTest]
SET dFRate = (dFCharge/(dSCharge+dACharge))
Also need to INSERT INTO 3 columns from a Table called tblFinanceP by looking up/Union or Join (not sure what to use) called vcTNum that is in bother the tblFinacneP and tblCIDetailsTest.
INSERT INTO [GDev].[dbo].[tblCIDetailsTest] AS Details
SELECT iPNum, iPCount, iZone
FROM [GrEDI].[dbo].[tblFinanceP] AS EDI
where EDI.vcTNum = GDev.dbo.tblCIDetailsTest.vcTN
View 1 Replies
View Related
Jul 20, 2005
Hi everybody,I just wrote my first two triggers and from the minimal amount of testing Ihave done, they work! However, I was hoping I could get some feedback fromthose of you more experienced in writing triggers.Here is the first one:CREATE TRIGGER DecreInters ON InteractionFOR DELETEASdeclare @stu INTdeclare @num INTselect @stu = Student_FK from deletedselect @num = (select Inters from Student where Student_Key = @stu)UPDATE StudentSET Inters = @num - 1FROM StudentWHERE Student.Student_Key = @stuHere is the second one:CREATE TRIGGER IncreIntersON InteractionAFTER INSERTASdeclare @stu INTdeclare @num INTdeclare @last_rec INTselect @last_rec = @@IDENTITYselect @stu = (select Student_FK from Interaction where Interaction_ID =@last_rec)select @num = (select Inters from Student where Student_Key = @stu)UPDATE StudentSET Inters = @num + 1FROM StudentWHERE Student.Student_Key = @stuAre there any shortcuts I could use or things I could do to make thesetriggers more efficient. Please give me some feedback and let me know ofany problems that might possibly be caused due to my doing this improperly.Thanks ahead,Corey
View 1 Replies
View Related
Oct 24, 2007
We have trigger on a table. The trigger implementation is to insert a record in another table. If any error occurred in the trigger then the trigger should log the error to a file on the file system.
CREATE TRIGGER [myTRIGGER] ON [dbo].[MyTest]
AFTER INSERT
AS
declare @errorcode int;
INSERT INTO MySecondTable (id, myvalue) values (null, 'hey')
set @errorcode=@@ERROR
if (@errorcode <>0)
print 'Error occurred with error code "' + CONVERT(varchar, @@ERROR) + '"'
Problem
If the insert statement fails, for example because of a null violation, then trigger aborts and never reaches the next step in the trigger T-SQL code.
IS this a limitation or there's somthing wrong on the above code?
Thanks
View 6 Replies
View Related