Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working with an older project. It was originally created as an MS Access front end and a Jet backend. The user names and passwords (security is not much of a concern here) were stored in plain text in a backend user table. Very simple system.

Later on, the backend was converted to MS SQL. They kept the same user table system. The front end has a single SQL login. So when the thing starts up, it logs into SQL right off the bat (the SQL credentials are just hard coded into the code) and then pops a login screen that accesses the user table I mentioned above. Again, very simple.

But now we have a bit of a problem. They want me to add some auditing capabilities for a few areas of the program. I've added the triggers needed and an audit table. No big deal, but I need the triggers to know who's logged in so it posts the correct user to the audit table. I don't want to create separate SQL users at this time. It impacts too much of the system for that to happen right now.

I thought a global temp table (1 column, 1 row) would work where I'd store the user but that's global to everyone, not just the connection because there's a single SQL login I'm guessing. It works, but it posts the most recently logged in user so it doesn't track things correctly. SO subsequent users overwrite that table each time. I read something about "context" info but it didn't seem like that was the solution either.

I've done a lot of searching in the last couple of days on how to handle this and I'm not coming up with anything that solves this problem. Any bright suggestions out there (other than creating and managing a load of SQL users and the front end tools for them to manage them)?

TIA,

AR.
Posted

1 solution

I guess you have the username of the person who is logged in and working in application.

Add one more column to your main tables for username and update it with the username who is modifying it. That will hold the information that who has modified current record.

now store the same column in your trigger table and this way you can maintain the history of modification.

Hope this helps.
 
Share this answer
 
Comments
avianrand 21-Nov-14 12:06pm    
Oh, that seems like a good idea. So you're saying to add a column to the trigger table to store the user that makes whatever mods are made to it? So if the data is added new, store the user name there, if it's updated, store it there too. Deletes get a little trickier. I guess I'd store the user name in the row first and then do the delete. The "deleted" table in the trigger would still have that value in it.

I'm looking into the context_info idea right now but if that doesn't pan out, your idea should work. Thanks.
Shweta N Mishra 22-Nov-14 2:51am    
Yeah, Why dont you maintain a flag for delete, I mean do not delete the record just maintain a record which says that its deleted and dont use that record for any other purpose, in that way you can have deleted records information with user details too.

But its not good practice if data in table is huge.
avianrand 26-Nov-14 21:28pm    
I was going to do that but it meant rewriting a ton of existing code to handle the fact that rows were still there but marked as deleted. It got more complicated than I wanted it to be. Easier to delete and post to log.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900