C# windows 应用程序中不存在数据库

问题描述 投票:0回答:0

我有一个名为 golds.mdf 的 localdb 数据库,当我备份它时,它说它不存在。即使 CRUD 操作完全正常,但在进行备份时,它给我的错误是它不会退出。

按照我的连接字符串。

<add name="cs" connectionString="Data Source(LocalDB)\MSSQLLocalDB;AttachDbFilename='|DataDirectory|\golds.mdf';Integrated Security=True"/>

并遵循备份代码。

string fullPath = "";

string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;

fullPath = (System.IO.Path.GetDirectoryName(executable));
AppDomain.CurrentDomain.SetData("DataDirectory", fullPath);

fullPath = fullPath + "\golds.mdf";
string insert = @"backup database ['" + fullPath + "'] to disk ='" + BackupPath.Text + "\" + currentdateInPer + ".bak'";
int r = database.setData(insert);
c# database-backups localdb
© www.soinside.com 2019 - 2024. All rights reserved.