Re: Is it possible to restore SQL database from my VB application ? -VB question.
- From: "Aykut" <aykut.canturk@xxxxxxxxxxxxxxx>
- Date: Wed, 3 Jan 2007 10:30:47 +0200
yes, using master database solved the problem. thank you
"Mark McGinty" <mmcginty@xxxxxxxxxxxxxxx> wrote in message
news:uoqzTFsLHHA.4992@xxxxxxxxxxxxxxxxxxxxxxx
"Aykut" <aykut.canturk@xxxxxxxxxxxxxxx> wrote in message
news:uHIZ5QlLHHA.1816@xxxxxxxxxxxxxxxxxxxxxxx
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
Does the connection string reference the db you want to restore? Try
changing it to master.
-Mark
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 ?
.
- References:
- Prev by Date: Re: Is it possible to restore SQL database from my VB application ? -VB question.
- Next by Date: closing VB6 ADO recordset takes much too long with SQL Server 2005
- Previous by thread: Re: Is it possible to restore SQL database from my VB application ? -VB question.
- Next by thread: closing VB6 ADO recordset takes much too long with SQL Server 2005
- Index(es):
Relevant Pages
|