473,698 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get .NET user ID from SQL Server trigger

I have an ASP.NET application that performs ADO.NET commands that cause
triggers to be run in SQL Server 2000.

My question is how would I best access the user ID from my custom .NET
Principal in the trigger (the trigger stores audit information and
needs the user ID)?

I'm using the same SQL Server user/pass on every connection to
facilitate connection pooling, so it's not available that way.

I've seen references to using SQL Server's CONTEXT_INFO or creating a
table to hold session data. I could also do something like this:

"set @userid='bob'; insert into customer values (1,2,3);"

but I'm not sure how to access that userid variable from the trigger
that will be fired.

Any advice would be appreciated. Thanks!

Feb 23 '06 #1
4 3630
Where is the trigger? On the user table? If so, make sure the trigger is on
insert and look at the inserted value. If you are on another table, this is
problematic and you will need to find the information from the user table,
which may or may not be possible.

WIthout more information, I can only shoot in the dark. :-)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"d0*******@snea kemail.com" wrote:
I have an ASP.NET application that performs ADO.NET commands that cause
triggers to be run in SQL Server 2000.

My question is how would I best access the user ID from my custom .NET
Principal in the trigger (the trigger stores audit information and
needs the user ID)?

I'm using the same SQL Server user/pass on every connection to
facilitate connection pooling, so it's not available that way.

I've seen references to using SQL Server's CONTEXT_INFO or creating a
table to hold session data. I could also do something like this:

"set @userid='bob'; insert into customer values (1,2,3);"

but I'm not sure how to access that userid variable from the trigger
that will be fired.

Any advice would be appreciated. Thanks!

Feb 23 '06 #2
connection pooling makes this difficult. the usual trick is a table with
userid by spid, or a conntection setting (like hostname).

i've switched to all procs requiring user login be passed (so they can
validate access and get the userid), and adding lastmodifiedby and
lastmodifieddat e to all tables. then the triigers have access.

-- bruce (sqlwork.com)


<d0*******@snea kemail.com> wrote in message
news:11******** *************@t 39g2000cwt.goog legroups.com...
I have an ASP.NET application that performs ADO.NET commands that cause
triggers to be run in SQL Server 2000.

My question is how would I best access the user ID from my custom .NET
Principal in the trigger (the trigger stores audit information and
needs the user ID)?

I'm using the same SQL Server user/pass on every connection to
facilitate connection pooling, so it's not available that way.

I've seen references to using SQL Server's CONTEXT_INFO or creating a
table to hold session data. I could also do something like this:

"set @userid='bob'; insert into customer values (1,2,3);"

but I'm not sure how to access that userid variable from the trigger
that will be fired.

Any advice would be appreciated. Thanks!

Feb 23 '06 #3
In my example the trigger would be on the customer table. There might
not even be a user table. 'bob' is the information I need to get at
(which isn't stored in the customer table (unless I add it for just
this purpose)).

Feb 23 '06 #4
Thanks for the reply.

I don't really like making the session table. I guess I'll have to add
lastmodifiedby to the tables to get it. How would you get the user on
a delete trigger? I guess it would have to be one of the other
methods. Hmm..

Yeah, it would be easier without connection pooling.

Feb 23 '06 #5

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

Similar topics

3
2575
by: Jorge Pinto | last post by:
Hey folks, I have an user A connected to database DB. On NT this user is logged as B. So, I want to create a trigger to see when the user tries to connect the database, it checks to see if user connection and user logged on NT is the same. Do I have a variable that returns my user logged on NT ? My set variables has the user connect on NT, so is there any possibility to read this variable on the server ??
2
8800
by: Ryan | last post by:
I have a table in my database on SQL Server which holds a file name that refers to a file that is stored on the server. I would like to create a trigger to delete this file from the server if the row in the table is deleted. I have been trying to use this command in a trigger (<filename> is the name and path of the file): xp_cmdshell "delete <filename>" If some one could please help I would appreciate it very much. I would love a...
2
11794
by: Bob Ganger | last post by:
Hello, I am working on a project using SQL Server 2000 with a database containing about 10 related tables with a lot of columns containing text. The total current size of the database is about 2 Gig. When I delete data from the database, it takes a lot of system resources and monopolizes the database so that all other query requests are slow as mud! Ideally, I would like to be able to issue delete commands to the database on a...
3
1862
by: Robert Hogan | last post by:
Hello all, I have a client with an application that they have purchased, it stores its data on SQL server 2000 and so I am able to do reports and some small VB apps that use the data. I can't however make any significant changes to the app itself, just what it allows you to configure. The system records jobs, when a job is closed the client want a prompt to pop-up asking if they want to record that the job is closed in a
1
8123
by: Rudolf Bargholz | last post by:
Hi, DB2 v7.1 FP3 on Windows 2003 I am trying to acheive the following: create trigger ADD_LHL after insert on MAINTABLE for each row mode db2sql insert into LOGTABLE
2
1087
by: Gianmaria I. | last post by:
Hi, that's my problem.. i hve a pege where users can uload a text file and leave an e-mail address.. when upload finished.. my server start working on this file.. and later sends he resultin file to the user's email. Now.. i've tried this ...but my user have to stay on that page with his browser or the server stops working.... how can i do to let the user leave the page just when upload is ok.. and have my serer coninue working.. on user's...
5
2644
by: Mike Mascari | last post by:
I'd like to ensure that the creation of a department also implies the creation of two to eight projects; no more, no less: CREATE TABLE departments ( department text primary key not null ); CREATE TABLE projects ( project text primary key not null, department text not null
6
3939
by: hemant.singh | last post by:
Hi all, I am trying to get a way by which I'll know exactly when user goes out of my site by clicking on close button in browser, So that w/e user click close button in browser, I can send a signal to server. This seems to be achievable with body unload events, but it is little too much, as even if user navigate within my site, this event will be generated, this can be avoided by handling onclick of each link, so that I'll know exactly...
1
9081
by: madhupk | last post by:
this is regarding C trigger function in postgresql 8.2 The function trigf reports the number of rows in the table ttest and skips the actual operation if the command attempts to insert a null value into the column x. (So the trigger acts as a not-null constraint but doesn't abort the transaction.) First, the table definition: CREATE TABLE ttest ( x integer );
0
8672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8892
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7712
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.