Ok, I've been at this for about 3 days now and I'm sorry if my constant "restore" questions are getting old but I've finally figured out exactly what's going wrong and I think I'm offically SOL.
I need to (through code since none of my clients will have SQL Server) Backup and Restore my programs SQL database at the push of a button. Backup works just fine, but Restore keeps giving me an error saying that it can't restore because people are logged on to the database. The problem is, there is only one person logged on to the database I'm trying to backup and that's me sending the "RESTORE" command to the database. So how can I tell MSDE/SQL to Restore the database, without first connecting to the database?
Here is some test code I made:
Private Sub Command2_Click()
'N473 ******************************* N473
'N473 * Backup/Restore the Database * N473
'N473 ******************************* N473
Dim rsUsers As ADODB.Recordset
Dim m_cn As ADODB.Connection
Dim intResponse As Integer
On Error GoTo GeneralError
' Open the Connection[/code]
Set m_cn = New ADODB.Connection
m_cn.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog = TagLinkSQLCS; Data Source = " & txtComputerName.Text & ";Initial File Name = C:\PROGRA~1\TAGLINK\DATA\TagLinkSQL.mdf"
m_cn.CursorLocation = adUseClient
m_cn.Open
' Restore the Backup
m_cn.Execute ("RESTORE DATABASE [TagLinkSQLCS] FROM DISK = N'C:\Program Files\TagLink\Data\TagLinkBackup.dat' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY"
MsgBox "Restore Completed successfully", vbOKOnly, "TESTING"
Exit Sub
GeneralError:
MsgBox Err.Description, vbOKOnly, "TESTING"
rsUsers.Close
m_cn.Close
Set rsUsers = Nothing
Set m_cn = Nothing
End Sub
The bold text is where I restore the database. The Restore syntax is correct but SQL says I'm not allowed to Restore because m_cn is connected to the database. How am I suppose to tell SQL to restore, if I can't connect to SQL to send the command?
Thank you
-N473
I need to (through code since none of my clients will have SQL Server) Backup and Restore my programs SQL database at the push of a button. Backup works just fine, but Restore keeps giving me an error saying that it can't restore because people are logged on to the database. The problem is, there is only one person logged on to the database I'm trying to backup and that's me sending the "RESTORE" command to the database. So how can I tell MSDE/SQL to Restore the database, without first connecting to the database?
Here is some test code I made:
Private Sub Command2_Click()
'N473 ******************************* N473
'N473 * Backup/Restore the Database * N473
'N473 ******************************* N473
Dim rsUsers As ADODB.Recordset
Dim m_cn As ADODB.Connection
Dim intResponse As Integer
On Error GoTo GeneralError
' Open the Connection[/code]
Set m_cn = New ADODB.Connection
m_cn.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog = TagLinkSQLCS; Data Source = " & txtComputerName.Text & ";Initial File Name = C:\PROGRA~1\TAGLINK\DATA\TagLinkSQL.mdf"
m_cn.CursorLocation = adUseClient
m_cn.Open
' Restore the Backup
m_cn.Execute ("RESTORE DATABASE [TagLinkSQLCS] FROM DISK = N'C:\Program Files\TagLink\Data\TagLinkBackup.dat' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY"
MsgBox "Restore Completed successfully", vbOKOnly, "TESTING"
Exit Sub
GeneralError:
MsgBox Err.Description, vbOKOnly, "TESTING"
rsUsers.Close
m_cn.Close
Set rsUsers = Nothing
Set m_cn = Nothing
End Sub
The bold text is where I restore the database. The Restore syntax is correct but SQL says I'm not allowed to Restore because m_cn is connected to the database. How am I suppose to tell SQL to restore, if I can't connect to SQL to send the command?
Thank you
-N473