我得到错误“数据库'服装'不存在。确保正确输入名称。 BACKUP DATABASE异常终止。 [英] i get the Error "Database 'Garment' does not exist. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.

查看:107
本文介绍了我得到错误“数据库'服装'不存在。确保正确输入名称。 BACKUP DATABASE异常终止。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bool bBackUpStatus = true;
            Cursor.Current = Cursors.WaitCursor;
            if (Directory.Exists(@"D:\SQLBackup"))
            {
                if (File.Exists(@"D:\SQLBackup\wcBackUp1.bak"))
                {
                    if (MessageBox.Show(@"Do you want to replace it?", "Back", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        File.Delete(@"D:\SQLBackup\wcBackUp1.bak");
                    }
                    else
                        bBackUpStatus = false;
                }
            }
            else
                Directory.CreateDirectory(@"D:\SQLBackup");
            if (bBackUpStatus)
            {
                //Connect to DB
                SqlConnection connect;
                string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bin\Debug\Garment.mdf;Integrated Security=True;Asynchronous Processing= True ;User Instance=True";
                connect = new SqlConnection(con);
                connect.Open();
                //-----------------

                //Execute SQL---------------
                SqlCommand command;
                command = new SqlCommand(@"backup database Garment to disk ='E:Garment.bak' with init,stats=10", connect);
                command.ExecuteNonQuery();
                //--------------

                connect.Close();

                MessageBox.Show("The support of the database was successfully performed", "Back", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

推荐答案

检查Garment.mdf数据库是否存在于位置| DataDirectory | \ bin \Debug \ 。
Check that the Garment.mdf database exists in location |DataDirectory|\bin\Debug\.


即使文件名是Garment.mdf,也许数据库没有被附加为Garment。将您的连接字符串修改为:'



Maybe the database is not being attached as Garment even though the file name is Garment.mdf. Modify your connection string to :'

string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bin\Debug\Garment.mdf;Integrated Security=True;Asynchronous Processing= True ;User Instance=True";


即使文件,也许数据库没有作为Garment附加名字是Garment.mdf。将您的连接字符串修改为:'



Maybe the database is not being attached as Garment even though the file name is Garment.mdf. Modify your connection string to :'

string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\bin\Debug\Garment.mdf;Database=Garment;Integrated Security=True;Asynchronous Processing= True ;User Instance=True";





记下连接字符串中的数据库关键字。



Take note of the Database keyword in the connection string.


这篇关于我得到错误“数据库'服装'不存在。确保正确输入名称。 BACKUP DATABASE异常终止。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆