查询还原数据库的问题 [英] problem of restore database with query

查看:139
本文介绍了查询还原数据库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi.i想通过这些查询还原数据库,但是遇到exeption错误

hi.i want to restore database with these query but encountered with error of exeption

User does not have permission to alter database 'alaki' or the database does not exist.
ALTER DATABASE statement failed.


我的代码是:


my code is:

try
                {
                    string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\alaki.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                    SqlConnection connect = new SqlConnection(con);
                    SqlCommand cmd = new SqlCommand();
                    connect.Open();
                    string s1 = "ALTER DATABASE alaki SET OFFLINE WITH ROLLBACK IMMEDIATE";
                    string s2 = "ALTER DATABASE alaki SET SINGLE_USER";
                    string query = " RESTORE DATABASE alaki FROM DISK ='" + path + "'" + "WITH  FILE = 1,  KEEP_REPLICATION,  NOUNLOAD,  REPLACE,  STATS = 10";


                    cmd.CommandText = s1;
                    cmd.Connection = connect;
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = s2;
                    cmd.Connection = connect;
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = query;
                    cmd.Connection = connect;
                    cmd.ExecuteNonQuery();

                    connect.Close();
                    MessageBox.Show("restor ok");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("error");


如果我删除


if i delete

cmd.CommandText = s1;
  cmd.Connection = connect;
  cmd.ExecuteNonQuery();

  cmd.CommandText = s2;
  cmd.Connection = connect;
  cmd.ExecuteNonQuery();


从我的代码中出现了一个错误提示:




from my code one error exeption appeared:



The file 'H:\Visual Studio 2005\Projects\WindowsApplication16\WindowsApplication16\bin\Debug\alaki.mdf' cannot be overwritten.  It is being used by database 'H:\VISUAL STUDIO 2005\PROJECTS\WINDOWSAPPLICATION16\WINDOWSAPPLICATION16\BIN\DEBUG\ALAKI.MDF'.
File 'alaki' cannot be restored to 'H:\Visual Studio 2005\Projects\WindowsApplication16\WindowsApplication16\bin\Debug\alaki.mdf'. Use WITH MOVE to identify a valid location for the file.
The file 'H:\Visual Studio 2005\Projects\WindowsApplication16\WindowsApplication16\bin\Debug\alaki_log.ldf' cannot be overwritten.  It is being used by database 'H:\VISUAL STUDIO 2005\PROJECTS\WINDOWSAPPLICATION16\WINDOWSAPPLICATION16\BIN\DEBUG\ALAKI.MDF'.
File 'alaki_log' cannot be restored to 'H:\Visual Studio 2005\Projects\WindowsApplication16\WindowsApplication16\bin\Debug\alaki_log.ldf'. Use WITH MOVE to identify a valid location for the file.
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
RESTORE DATABASE is terminating abnormally.



请帮助我,因为我很累.谢谢了很多.



pleaze help me because i am very tired.thank''s a lot

推荐答案

您的错误代码的定义在这里;
http://support.microsoft.com/kb/221465 [还原数据库 [
Your error code''s definition is in here;
http://support.microsoft.com/kb/221465[^]

Basically a process is holding the file or you are trying to overwrite an existing file that is in use.
Please follow how to restore the database;

Restoring database[^]

Good luck




检查对数据库的SQL用户访问,似乎没有更改数据库的权限...

谢谢,
Siva
Hi,

Check the SQL user access on the database, it seems it has no rights to alter database...

Thanks,
Siva


在您的链接中非常感谢orc_orc_orc清楚地描述了问题,但没有提供实际的示例代码来解决我的问题
thanks alot orc_orc_orc in your link describing the problem clearly but do not have present a practical way example a code than remove my problem


这篇关于查询还原数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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