Hey all,
I am trying to include a (sqlbackup).bak file in my project for deployment.
I am able to include the file just fine, but If i run an sql script in code to restore a database from it, I get an access denied error.
Just to double check my code, I referenced the file directly (without including it in the project) and i was able to use it just fine.
Any idea how to get around this? I really need to be able to include this file so it deploys with the application.
Here's a sample of the code that will be accessing the file (CleanDB.bak is the file in question).....
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = My.Settings.ConnectionString
con.Open()
cmd.Connection = con
sql = "CREATE DATABASE " & DBName
cmd.CommandText = sql
cmd.ExecuteNonQuery()
sql = "RESTORE DATABASE " & DBName & " FROM DISK = N'" & Application.StartupPath & "\CleanDB.bak' WITH FILE = 1, MOVE N'" & DBName & "' TO N'" & DBPath & "',REPLACE"
cmd.CommandText = sql
cmd.ExecuteNonQuery()
con.Close()