Is there a way to log database name when auditing logins in SQL Server (2005 and above)?
I basically want to log the username and the database name the user successfully connected to.
I have tried profiler, databasename column is blank.
This question came from our site for professional and enthusiast programmers.
Your best bet is to use a Logon Trigger
Just make sure your trigger captures
Just be careful with logon triggers. If you mess them up you can prevent any logins, because when they fail they cause the login to fail and then you have to use a workaround to get into the system and drop the trigger so you can fix it.
Don't let that hinder you though, just know you need to test them out thoroughly before you go throwing them onto a production server.