473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Want to create a new transaction

Dear all,

I have created some triggers on tables for audit purposes. I want this
process to be outside of the existing transaction for the application
making the changes to the tables. - if for whatever reason an insert
into the audit tables fails, I do not want the calling application to
fail!

How is this done in TSQL?

This is bound to be simple but its eluding me so far...

Many thanks in advance.
Andy
Jul 20 '05 #1
4 6158
It is simple ... I don't think you can't do it (in SQL).

Transactions in a trigger participate in the open transaction, so you roll
back the outer one you rollback the inner one.

You can invoke an extended (xp_) procedure in the trigger to write a log
outside of the outer transaction.
XP's are really just an call to an external program that runs outside of the
sqlserver (as well as outside the transaction).

If you can't write your own XP DLL , you can invoke an EXE via the standard
xp_cmdshell.

XP's may be turned off for security reasons.

Also since an errant XP could lock up the database server (requireing a
reboot), they should be used with care.
"Andy" <an*********@hotmail.com> wrote in message
news:8f**************************@posting.google.c om...
Dear all,

I have created some triggers on tables for audit purposes. I want this
process to be outside of the existing transaction for the application
making the changes to the tables. - if for whatever reason an insert
into the audit tables fails, I do not want the calling application to
fail!

How is this done in TSQL?

This is bound to be simple but its eluding me so far...

Many thanks in advance.
Andy

Jul 20 '05 #2
Reread you question again and saw you wanted the inner one to be rolled
back.

I haven't tried it since it didn't work well in previous version, but by
naming your inner transaction you can do an rollback to the named checkpoint
and continue on.

This is moot if the insert is failing implicitly (via SQL Server) and not
through an explicit rollback.

What's the problem your getting with your audit trail?

"David R Rawheiser" <ra*******@hotmail.com> wrote in message
news:YZ********************@comcast.com...
It is simple ... I don't think you can't do it (in SQL).

Transactions in a trigger participate in the open transaction, so you roll
back the outer one you rollback the inner one.

You can invoke an extended (xp_) procedure in the trigger to write a log
outside of the outer transaction.
XP's are really just an call to an external program that runs outside of the sqlserver (as well as outside the transaction).

If you can't write your own XP DLL , you can invoke an EXE via the standard xp_cmdshell.

XP's may be turned off for security reasons.

Also since an errant XP could lock up the database server (requireing a
reboot), they should be used with care.
"Andy" <an*********@hotmail.com> wrote in message
news:8f**************************@posting.google.c om...
Dear all,

I have created some triggers on tables for audit purposes. I want this
process to be outside of the existing transaction for the application
making the changes to the tables. - if for whatever reason an insert
into the audit tables fails, I do not want the calling application to
fail!

How is this done in TSQL?

This is bound to be simple but its eluding me so far...

Many thanks in advance.
Andy


Jul 20 '05 #3
Look at BOL under 'triggers, ROLLBACK TRANSACTION'

You must use the SAVE TRANSACTION statement to do a partial rollback in a
trigger, even if it is always called in autocommit mode. This is illustrated
by the following trigger:

CREATE TRIGGER TestTrig ON TestTab FOR UPDATE AS
SAVE TRANSACTION MyName
INSERT INTO TestAudit
SELECT * FROM inserted
IF (@@error <> 0)
BEGIN
ROLLBACK TRANSACTION MyName
END
Gary"Andy" <an*********@hotmail.com> wrote in message
news:8f**************************@posting.google.c om...> Dear all,

I have created some triggers on tables for audit purposes. I want this
process to be outside of the existing transaction for the application
making the changes to the tables. - if for whatever reason an insert
into the audit tables fails, I do not want the calling application to
fail!

How is this done in TSQL?

This is bound to be simple but its eluding me so far...

Many thanks in advance.
Andy


Jul 20 '05 #4
check out www.redmatrix.com and their product SQL Audit

Oscar...

"Andy" <an*********@hotmail.com> wrote in message
news:8f**************************@posting.google.c om...
Dear all,

I have created some triggers on tables for audit purposes. I want this
process to be outside of the existing transaction for the application
making the changes to the tables. - if for whatever reason an insert
into the audit tables fails, I do not want the calling application to
fail!

How is this done in TSQL?

This is bound to be simple but its eluding me so far...

Many thanks in advance.
Andy

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alan | last post by:
Gidday people, I had a bit of a problem this morning. I think I've got it sorted now, but I wonder if anyone can shed some light. I have a plain VBS WHS file that instantiates a component that...
2
by: CJM | last post by:
I have page that starts a transaction and runs several StoredProcs before committing or rollingback. An initial SP create a header records, and then the code goes into a loop and runs 4 other SP's...
2
by: Robin Tucker | last post by:
I have some code that dynamically creates a database (name is @FullName) and then creates a table within that database. Is it possible to wrap these things into a transaction such that if any one...
4
by: SAEED BASUDAN | last post by:
Hi i have 2 Table first one : Customer with 4 Fields : cst_no,cst_name,total_Debit,tot_credit second one : Transaction with 5 Fields : Trns_no,Trns_Date,cst_no,debit,credit MY QUESTION:...
4
by: Graham Like | last post by:
I read a lot about serialising things to XML. Can someone give me some examples of why I would want to do this? I seem to be missing the point.
0
by: CJM | last post by:
I'm executing a series of SQL Server stored procs in one ASP page. They are wrapped within an ADO transaction. The reason for several SP calls is that the SPs are used individually elsewhere in the...
0
by: Solution Seeker | last post by:
Hi, We are using vb.net for creating a Windows Application. We are using layered approach, with a UI layer, Logic, Db Access layer etc. we are encountering a peculiar problem when we try to...
17
by: Jeffrey W. Baker | last post by:
Greetings, I have a 23GB data table upon which I am building a primary key of three columns. The data is mounted in a 137GB device and pg_xlog is mounted on a separate 3.5GB device. I have...
0
by: vaibhavsumant | last post by:
<project name="DBCreate" default="usage" basedir="."> <property name="user" value="db2admin"/> <property name="passwd" value="db2admin"/> <property name="dbprefix" value=""/> <property...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.