当我从安装程序中备份(安装时)时显示错误 [英] Error showing when i take backup from my setup(installed it)

查看:60
本文介绍了当我从安装程序中备份(安装时)时显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个项目,并将该安装程序安装在另一台计算机上,然后我无法备份数据库

C#中的Windows应用程序
visualstudio 2008

源代码
-------------------------------------------------- --------------

I created a project and i installed that setup on another computer,then i can''t take backup of database

windows application in c#
visualstudio 2008

source code
----------------------------------------------------------------

bool bBackUpStatus = true;
 
Cursor.Current = Cursors.WaitCursor;
 
if (Directory.Exists(@"c:\SQLBackup"))
{
if (File.Exists(@"c:\SQLBackup\wcBackUp1.bak"))
{
if (MessageBox.Show(@"Do you want to replace it?", "Back", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Delete(@"c:\SQLBackup\wcBackUp1.bak");
}
else
bBackUpStatus = false;
}
}
else
Directory.CreateDirectory(@"c:\SQLBackup");

SqlConnection connect;
string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\New.mdf;Integrated Security=True;User Instance=True";
connect = new SqlConnection(con);
connect.Open();
//----------------------------------------------------------------------------------------------------
 
//Execute SQL---------------
SqlCommand command;
command = new SqlCommand(@"backup database [C:\Users\Ravu\Desktop\Bill\Bill\bin\Debug\New.mdf] to disk ='c:\SQLBackup\New.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);


错误详细信息
--------------
有关调用
的详细信息,请参见此消息的末尾. 即时(JIT)调试,而不是此对话框.

**************异常文本**************


Error details
--------------
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.Data.SqlClient.SqlException: Could not locate entry in sysdatabases for database 'C:\Users\Ravu\Desktop\Bill\Bill\bin\Debug\New.mdf'. No entry found with that name. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Bill.MDIParent1.backUpToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\Ravu\Desktop\Bill\Bill\MDIParent1.cs:line 299
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

推荐答案

试试这个来备份

try this to take backup

private void backup(string filename, string databasename)
{
conn.Open();
                string sqlQuery = "Backup database " + databasename+ " To Disk = '" + filename + "'";
                cmd = new SqlCommand(sqlQuery, conn);
                cmd.ExecuteNonQuery();
conn.Close();
}



backup("type_your_desired_filename.bak","type_your_database_name");



backup("type_your_desired_filename.bak","type_your_database_name");


这篇关于当我从安装程序中备份(安装时)时显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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