Include File Issue - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Include File Issue

Midwest_TechMidwest_Tech Posts: 4Member
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
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()[/code]

Comments

Sign In or Register to comment.