473,396 Members | 1,871 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.

Task/transaction token by logging

Hallo All,

I'm making in my DB some logs.
I have a separate table containing:
ID,
Date,
Source,
Type,
ErrorNo,
Description

Acctualy the table struct is not immportand that's why I do not post
the script.
I have one procedure, which I call in my other function procedures,
triggers etc. with parameters.
This procedure (WriteToLog) is called, if in other procedures, triggers
is any validation, exception or only information which I would like to
log me separately, and it writes the record into this table.

But sometimes, it is very hard, to follow much logs, and I figured out,
if I could have something like transaction ID, task ID, it will be much
easier.

Firs idea was to, by going from procedures to other procedures, pass a
self generated token (ie. date with any additional number). But then, I
need to change everywhere where I call WriteToLog procedure the call
syntax.

Let's say that we have following situation:

Procedure1:

Action1
Select1
CompareOfValues1
exec WriteToLog

Action2
CompareOfValues2
exec WriteToLog

Action3
exec Procedure2
Procedure2:
Action1
exec WriteToLog
Select1
Insert1
Trigger1Started:
Action1
CompareOfValues1
exec WriteToLog
Action2
Trigger1Exit:
Procedure2Exit:
Procedure1Exit:

Now ... I could pass this my generated number, from SP to SP and so on.
But I would like to now, does the MS SQL server has something what
identifies transaction like descripted below.

In this case, I do not need to pass any number, only I need to get this
number anyhow in SP WriteToLog, and insert it into my log table.
Any sugestions?

Thank's in advance.

Mateusz

Jul 23 '05 #1
3 1640
[posted and mailed, please reply in news]

Matik (ma****@sauron.xo.pl) writes:
Now ... I could pass this my generated number, from SP to SP and so on.
But I would like to now, does the MS SQL server has something what
identifies transaction like descripted below.

In this case, I do not need to pass any number, only I need to get this
number anyhow in SP WriteToLog, and insert it into my log table.
Any sugestions?


It sounds like this is a case where SET CONTEXT_INFO could come into
use. With this command you set a value for the process in
sysprocesses.context_info, and thus your WriteLog could read from this
place. context_info is binary, but you can convert forth and back from
a string if you like.

Read more about SET CONTEXT_INFO in Books Online.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
Hello Erland,

Thank you for fast reply. Unfortunately, this option is not usefull for
me.
I cannot do this in my WriteToLog procedure. I need to set this option
at the beginning of each chain which I call, to get the value
consistent threw whole callstack.

I was thinking more, the SQL server is doing somethin like this
already, and I could use this transaction stamp for my logging.
Some more ideas?

Thank You

Mateusz

Jul 23 '05 #3
Matik (ma****@sauron.xo.pl) writes:
Thank you for fast reply. Unfortunately, this option is not usefull for
me.
I cannot do this in my WriteToLog procedure. I need to set this option
at the beginning of each chain which I call, to get the value
consistent threw whole callstack.
And that is precisely how you can use SET CONTEXT_INFO. You call SET
CONTEXT_INFO prior to starting the task, and in WriteToLog you get
the value from sysprocesses.
I was thinking more, the SQL server is doing somethin like this
already, and I could use this transaction stamp for my logging.


There is no such value that you can access.

And in any case, SET CONTEXT_INFO is more general, since it persists
over transaction boundaries.

The other option would be to have a temp table to retrieve the value
from.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4

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

Similar topics

3
by: Thiko | last post by:
Hi I take one nightly full database backup at 02:00 and backup the transaction log to one backup set every 15mins. The commands to do this are as follows and are set up to run as database...
5
by: J. Yuan | last post by:
Hi, I am working on a checkout/inventory system. How can I make a button that when pressed, would update the previous fields transaction number to a table (for example, -3 printers, so that...
15
by: Zeng | last post by:
Hi, The bigger my C# web-application gets, the more places I need to put in the tedious retrying block of code to make sure operations that can run into database deadlocks are re-run (retried)...
6
by: pgmoscatt | last post by:
I have just moved over to PostGres after using MySQL. In MySQL I could issue the command SHOW TABLES within a database to show what tables are within. I tried to do this with PostGres and I...
1
by: Bernd Hohmann | last post by:
I have a table with CHAR(8), CHAR(5), DOUBLE, DOUBLE, VARCHAR(40), DOUBLE, CHAR(1). This should be roundabout less than 100 bytes per row. The primary key is the CHAR(8)+CHAR(5). The table...
9
by: Eugene F | last post by:
The database is currently in the circular logging mode (no log archiving). I want to track the database transaction log switch history in form of (switch-timestamp, active-log-sequence-number) to...
5
by: Allan Ebdrup | last post by:
I'm using dotNet 2.0 and System.Transactions to run transactions that span multiple database queries, Now I would like to log any Sql errors that occur in the transaction, but when I insert the...
3
by: GaryDean | last post by:
I'm using TransactionScope as follows... using TransactionScope myScope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString =...
2
by: Lan Mind | last post by:
Hello again everybody, My page: http://www.dockhawk.com/ I'm trying to implement some "session security" PHP script mentioned in the "Cross-site request forgery" section of this tutorials...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.