The problem is, my company makes a program that helps keep track of maintance on heavy machinery (like generators at the hoover damn, or Air Craft carriers) and we are currently migrating our database from Access to SQL Server (hence why I know nothing about SQL). To insure that no history is lost in case OSHA comes to check on our customers, we allow for a Backup/Restore option. Because most of our users know nothing about computers, this should be a one click operation and only a small percentage of our clients will actually have SQL Server installed on their machine. Therefore, the restore needs to be done through code.
The problem I'm having is that when I click restore I get an error saying that there are users currently logged on to the server. So I've decided to ask the user, if they would like to automatically log everybody off of the system and continue with the restore. I was told the way to log everybody off, was with the Kill command. But when I execute command, I get the "User Process" error. My above post is what comes up when you run sp_who in the Query Analyzer, but I have no idea what that means. Which one of those needs to be logged off, and which ones are allowed to stay logged in before I can run a restore? How am I suppose to know who is ok, and who needs to be killed? Is there another way to get everybody off besides kill? If you don't know VB that's fine, just the logic would be a great help (although a code example would be nice if you could provide one).
Here is what I have so far:
' Open the SQL Connection
Set m_cn = New ADODB.Connection
m_cn.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog = *******SQLCS; Data Source = " & txtComputerName.Text & ";Initial File Name = C:\PROGRA~1\*******\DATA\*******SQL.mdf"
m_cn.CursorLocation = adUseClient
m_cn.Open
' Get the results from sp_who
Set rsUsers = New ADODB.Recordset
rsUsers.ActiveConnection = m_cn
rsUsers.Open m_cn.Execute("sp_who"
' Are their any users loged on to the System
If rsUsers.RecordCount > 1 Then
intResponse = MsgBox("There are " & rsUsers.RecordCount & " users loged on to the server at this time. Would you like to kick them off?", vbYesNo, app.Title)
' Kick users off the Server?
If intResponse = vbYes Then
Do While rsUsers.EOF = False
' is 'runnable' the only logons I can kill?
Select Case LCase(Trim(rsUsers.Fields("status"

))
Case "runnable"
[color] ' Kill this user based on the spid[/color]
m_cn.Execute ("KILL " & rsUsers.Fields("spid"

)
End Select
rsUsers.MoveNext
Loop
' Restore the Backup
m_cn.Execute ("RESTORE DATABASE [*******SQLCS] FROM DISK = N'C:\Program Files\*******\Data\*******Backup.dat' WITH FILE = 12, NOUNLOAD , STATS = 10, RECOVERY"

MsgBox "Restore Completed successfully", vbOKOnly, "TESTING"
End If
Else
' Nobody logged on, just restore the Database
m_cn.Execute ("RESTORE DATABASE [*******SQLCS] FROM DISK = N'C:\Program Files\*******\Data\*******Backup.dat' WITH FILE = 12, NOUNLOAD , STATS = 10, RECOVERY"

MsgBox "Restore Completed successfully", vbOKOnly, "TESTING"
End If
Thank you
-N473