Is it possible to restore SQL database from my VB application ? -VB question.
- From: "Aykut" <aykut.canturk@xxxxxxxxxxxxxxx>
- Date: Tue, 2 Jan 2007 11:56:07 +0200
I take a backup with the folloeing commands:
cn.open connectionstring
sqlstr = "BACKUP DATABASE uruntakip TO DISK = 'd:\backup.dat' "
cn.Execute sqlstr
cn.close
set cn = noting
then I try to restore it:
cn.open connectionstring
sqlstr = "RESTORE DATABASE uruntakip FROM DISK = 'd:\backup.dat' "
cn.Execute sqlstr
cn.close
set cn = noting
it cannot restore because databa is in use. okay, then I searched the net
and tried:
Dim srv As New SQLDMO.SQLServer
Dim rest As New SQLDMO.Restore
srv.Connect DatabaseServerName, DatabaseUserID, DatabaseUserPassWord
rest.Action = SQLDMORestore_Database
rest.Database = DataBaseName
rest.Devices = rest.Files
rest.Files = ''d:\backup.dat'"
rest.ReplaceDatabase = True
rest.SQLRestore srv
Set rest = Nothing
Set srv = Nothing
same error okay, then searched the net and tried to kill spid's
Dim rst As New ADODB.Recordset
dim cn as new adodb.connection
cn.open ConnectionString
Set rst = cn.Execute("sp_who")
If Not rst.BOF Then rst.MoveFirst
While Not rst.EOF
cn.Execute "KILL " & rst("spid")
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
cn.close
set cn = nothing
Now, I included dim statements to indicate that no connection stays open.
but it seems that the active connection I use to execute sql statements
makes the error "database in use". I also tried
ALTER DATABASE uruntakip SET SINGLE_USER WITH ROLLBACK IMMEDIATE
statement and didn't work.
Can I restore a Sql server 2000 database inside my visual basic application
?
.
- Follow-Ups:
- Prev by Date: Re: data mismatch error
- Next by Date: Re: Is it possible to restore SQL database from my VB application ? -VB question.
- Previous by thread: Re: data mismatch error
- Next by thread: Re: Is it possible to restore SQL database from my VB application ? -VB question.
- Index(es):
Relevant Pages
|