I'm writing a program that connects to MS SQL Server, on start up it clears some tables in one database, and repopulates them from another database. I would like this to only happen if there are no other connections to the database I'm clearing. Is there any way of checking the amount of active connections on a specfic database within code?
Checking active connections by user is also an option if thats the only way to do it as all connections to the database should be a specific user. If it's an admin I'm assuming it is via SQL Server Manager and want everything to behave as if they weren't connected. Google hasn't provided me with any answers as of yet, which is probably my fault, but i'm giving myself the benefit of the doubt and blaming Google. So I'll keep looking.
Thanks.