Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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)

----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.[][][]
---------------------------------------------
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);
Posted
Updated 6-Nov-12 16:11pm
v3

1 solution

I think your path is the problem: "C:\Users\Ravu\Desktop\Bill\Bill\bin\Debug\New.mdf" looks a very unlikely path to a SQL database. Make sure your code uses an absolute path.
 
Share this answer
 
Comments
ravuravu 6-Nov-12 10:49am    
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);
ravuravu 6-Nov-12 10:50am    
this my backup code hey pls help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900