I use sql server 2012 database to store data for my application
I want to make a backup and restore for the database from inside my application
I've Implemented sqlcommand to execute backup operation
Using Cmd As New SqlCommand() With {.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("JoyBoxArchiveCn").ConnectionString)}
Dim a = New SqlConnection
Dim Fnm As String = Server.MapPath("~\backup\test001.bak")
Cmd.CommandText = "backup database jbxarchive to disk='" & Fnm & "'"
Cmd.Connection.Open()
r = Cmd.ExecuteNonQuery
Cmd.Connection.Close()
and that does it ok
the problem is when I've tried to restore
Cmd.CommandText = "alter database jbxarchive set single_user with rollback immediate; "
Cmd.CommandText &= "restore database jbxarchive from disk='" & Fnm & "' with replace;"
Cmd.CommandText &= "alter database jbxarchive set multi_user;"
from management studio it works fine but from code behind I've got a security error that the current user does not have permission to restore database
please instruct me the correct way to backup and restore database from code behind
What I have tried:
from management studio it works fine but from code behind I've got a security error that the current user does not have permission to restore database