VB.NET

Moderators: seancampbell
Number of threads: 3904
Number of posts: 9886

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Include File Issue Posted by Midwest_Tech on 29 Jun 2010 at 2:44 PM
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()

Report
Re: Include File Issue Posted by Midwest_Tech on 29 Jun 2010 at 3:06 PM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.