Include File Issue

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).....

[code]Dim con As New SqlConnection
Dim cmd As New SqlCommand

con.ConnectionString = My.Settings.ConnectionString
cmd.Connection = con

cmd.CommandText = sql

sql = "RESTORE DATABASE " & DBName & " FROM DISK = N'" & Application.StartupPath & "CleanDB.bak' WITH FILE = 1, MOVE N'" & DBName & "' TO N'" & DBPath & "',REPLACE"
cmd.CommandText = sql


  • Never mind, I got it figured out.

    It was a file permission issue after all. I changed the permissions on the file, set it to always copy and it is now working.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion