May 5, 2011 at 2:02 pm
Hi
I have read somewhere that is is possible to define a loopback linked server ( pointing to the same source db )
and use in auditing scenarios to modify data outside of the currently running transaction.
This was an alternative to using table variable and generating events by I cannot get this to work.
I remember that there was so setting responsible for not starting a distributed transaction for this linked server and probably the linked server has to be using ODBC drivers.
Does anyone here knows about this approach, or is it just a myth ?
May 5, 2011 at 2:14 pm
mutobo (5/5/2011)
HiI have read somewhere that is is possible to define a loopback linked server ( pointing to the same source db )
and use in auditing scenarios to modify data outside of the currently running transaction.
This was an alternative to using table variable and generating events by I cannot get this to work.
I remember that there was so setting responsible for not starting a distributed transaction for this linked server and probably the linked server has to be using ODBC drivers.
Does anyone here knows about this approach, or is it just a myth ?
Well creating the Loopback Linked server is no big deal, but I don't see how this would help you at all;
DECLARE @server SYSNAME
set @server=@@SERVERNAME
EXEC master.dbo.sp_addlinkedserver @server = N'MyLoopbackServer',
@srvproduct = N'',
@datasrc = @@SERVERNAME,
@provider = N'SQLOLEDB',
@catalog='SandBox';
SP_TABLES_EX MyLoopbackServer
EXEC dbo.sp_DropServer 'MyLoopbackServer','DropLogins'
Lowell
May 5, 2011 at 2:38 pm
Actually I got this working by changing the linked server option:
EXEC master.dbo.sp_serveroption @server=N'LOOPBACK', @optname=N'remote proc transaction promotion', @optvalue=N'false'
and using the "EXEC() at" syntax:
exec ('update top(1) db_name.schema.table
set col = value
where col2= 2=value2') at LOOPBACK
but still would like to create a synonym to the table on the linked server and use line casual DML statement:
CREATE SYNONYM linkedtablename FOR LOOPBACK.db_name.schema.table
update top(1) linkedtablename
set col = value
where col2= 2=value2
but that does not work:
Msg 3910, Level 16, State 2, Line 1
Transaction context in use by another session.
May 5, 2011 at 5:23 pm
The remote transaction promotion technique is described in more detail here:
I used the same trick with sequence tables:
http://sqlblog.com/blogs/paul_white/archive/2010/10/19/sequence-tables.aspx
But it's hard to recommend this technique (it's quite slow, and there are many 'issues' waiting for you down this path). Why not use the traditional table variable technique?
CREATE TABLE dbo.Test (A INT NOT NULL);
BEGIN TRANSACTION;
DECLARE @Audit TABLE (A INT NOT NULL);
INSERT dbo.Test (A)
OUTPUT
inserted.A
INTO @Audit (A)
VALUES
(999);
ROLLBACK TRANSACTION;
SELECT * FROM dbo.Test;
SELECT * FROM @Audit
DROP TABLE dbo.Test;
Notice the audit data survives the rollback.
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply