We have an automated script to restore a Sybase database and then run our automated tests against it. Quite often we have a web server or interactive query tool connected to this database. These connections prevent the Sybase load with “…must have exclusive use of database to run load”.
How do I kick/kill/terminate all connections?
I’d like something similar to Sql Server’s alter database single_user with rollback immediate. This is a local Sybase instance so we have full admin rights.
Without knowing exactly what condition the script checks for, there are two things you need to do to guarantee exclusive use of a database (i) run “master..sp_dboption ‘your-db-name’, ‘single user’, false” to put it in single-user mode, and (ii) kill all existing users first with the “kill” command.
This is not difficult to put in a stored procedure — kill all connections using your database as their current database or having a lock in that database, and then try to set it to single-user mode. Then check if the single-user mode succeeded — you should allow for a repeated try since it is possible that a new user has connected again just when you’re setting it to single-user mode.
This is all not difficult to implement, but you will need some understanding of the ASE system tables. But primarily, I think you need to figure out exactly what it is your load script assumes to be the case and what it checks for.
There may be other solutions as well: if you can just lock the tables affected by your load script for example, that may also be a solution (and a simpler one). But this may or may not be possible, depending on what the load script exactly does and what is expects. So that would be question #1 to answer.
HTH,
Rob V.