开发者

DB Backup runs in Debug but not Release

开发者 https://www.devze.com 2023-03-07 01:19 出处:网络
I have a small c# wpf app for doing some simple calculations running off a Sql Express 2008 R2 db, and in the setup section is a backup button that runs the code

I have a small c# wpf app for doing some simple calculations running off a Sql Express 2008 R2 db, and in the setup section is a backup button that runs the code

                using (DTZDataContext db = new DTZDataContext())
                {
                    db.ExecuteCommand(string.Format("BACKUP DATABASE DtzDb TO DISK = '{0}'", filename));
                }

The connection string I am using is

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\DTZ.mdf;Integrated Security=True;User Instance=True;Database=DtzDb

I have confirmed there are no other open db connections at this point in the application and the backup runs fine in debug, but once I compile for release (running from VS or as standalone) I get the error:

Operating system error 32 “32(failed to retrieve text for this error Reason 15105)” BACKUP DATABASE is terminating abnormally.

How can I fix this, preferably without having to install Sql Management Studio on each machine and attaching the DB? What is the recommended way of doing backups? Why does it work in Debug but n开发者_JAVA百科ot Release.

Many Thanks


My bad... It turns out VS had changed the DataContext connection string to DTZConnectionString1 and made another settings file. Now I am using the correct connection string it is working fine.

No idea why the incorrect one worked in debug but not release.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号