|
|
|
อยากทราบการทำการสำรองข้อมูล (Backup Restore ) ด้วย C# + SQL Server 2005 ทำยังไงคะ ช่วยด้วยนะคะ |
|
|
|
|
|
|
|
Backup ผ่าน SQL Statement ครับ
Code (C#)
private void btnBack_Click(System.Object sender, System.EventArgs e)
{
string strSQL = null;
string strCon = null;
strCon = "Data Source=NITHI;Initial Catalog=master;Integrated Security=True";
System.Data.SqlClient.SqlCommand cmdBackup = new System.Data.SqlClient.SqlCommand();
SqlConnection1.ConnectionString = strCon;
SqlConnection1();
Cursor = Cursors.WaitCursor;
try {
strSQL = "BACKUP DATABASE Northwind ";
strSQL += "TO DISK = 'C:\\mybackup.bak' ";
strSQL += "WITH FORMAT, ";
strSQL += "NAME = 'myBackup'";
cmdBackup.Connection = SqlConnection1;
cmdBackup.CommandText = strSQL;
cmdBackup.ExecuteNonQuery();
Interaction.MsgBox("finish");
} catch (Exception ex) {
Interaction.MsgBox("Error");
}
Cursor = Cursors.Arrow;
SqlConnection1.Close();
cmdBackup.Dispose();
cmdBackup = null;
}
|
|
|
|
|
Date :
2011-08-19 16:45:15 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูบทความนี้น่ะครับ http://www.codeproject.com/KB/dotnet/SQL_Server_backup.aspx
|
|
|
|
|
Date :
2011-08-19 16:46:19 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณค่ะ ^^
|
|
|
|
|
Date :
2011-08-21 01:38:08 |
By :
จอย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Error ค่ะ ช่วยดูให้ด้วยนะคะ
|
|
|
|
|
Date :
2011-08-21 01:51:44 |
By :
จอย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
SqlConnection1 = new SqlConnection;
ประกาศไว้ข้างบนครับ
|
|
|
|
|
Date :
2011-08-21 07:12:17 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้คะ Error ตรง SqlConnection1 = new SqlConnection;
|
|
|
|
|
Date :
2011-08-21 14:17:33 |
By :
จอย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
SqlConnection1 = new SqlConnection();
|
|
|
|
|
Date :
2011-08-21 15:08:14 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|