Re: Is it possible to restore SQL database from my VB application ? -VB question.



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 ?









.



Relevant Pages

  • Is it possible to restore SQL database from my VB application ? -VB question.
    ... cn.open connectionstring ... it cannot restore because databa is in use. ... Dim srv As New SQLDMO.SQLServer ... ALTER DATABASE uruntakip SET SINGLE_USER WITH ROLLBACK IMMEDIATE ...
    (microsoft.public.vb.database.ado)
  • Re: Crud Design Question
    ... since you will use only one database, ... you could put the connectionstring in a single class, ... Maybe you should provide a private constructor, wich is called by the Load ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Crud Design Question
    ... since you will use only one database, ... you could put the connectionstring in a single class, ... Maybe you should provide a private constructor, wich is called by the Load ... public static void Load ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Accessing SqlServer(Express) data on the server
    ... As for the ASP.NET, it is built upon the .net framework, so generally all ... you can change the connectionstring to point to another ... manually create another database (named "MyASPNETDB" in SQL Express ... you can even use SQL Server authentication(specify username/password ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • programmatic database access
    ... I will use this class to do the gruntwork for a custom membership ... Second I need help with the programmatic access of the database. ... provider when it appears in the web.config membership provider tag. ... static string to hold the connectionString for the connection setup. ...
    (microsoft.public.dotnet.languages.csharp)