Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 UserID T-SQL

Author  Topic 

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-04-06 : 04:08:49
I am running into a strange issue. When I log on to sql 2005 using a trusted connection on my local machine, I write the SQL User_ID for myself to a specific table. This userID for some reason changes from time to time, why is this? For instance my user ID is 63, I can log on 2 minutes later and be user ID 64.

Is this because the last connection did not terminate properly, or something else? What is the better practice to us,so I am always identified as being the same person when I log on using the trusted connetion. This needs to be 100% because I am using it to release manual table locks (Manual locks are a column bit value I set, not using any SQL record locking feature).

In order to remove the locks off the correct records, I need to make sure the users ID is alwayws the same so the correct locks are removed.

Is there a better way to do this, or what's the issue, or if I don't use a trusted conection and rather use Mixed authentication mode and specify a username and passowrd, will this help?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-04-06 : 11:52:30
It sounds like you're getting the user id using the USER_ID function? That id is unique to each database, so depending on which database is the current database when you call that function, you will probably get different numbers.

You should rather record the user name, which you can get with the USER_NAME or SYSTEM_USER functions. They are different, so look them up and see which one will be best for your purposes.
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-04-06 : 22:11:05
I am always logging into the same db (it is done via my .net application automatically), and still I get a different User_ID. Any other sugestions or things to try?
Go to Top of Page
   

- Advertisement -