我有一个名为 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);