851166303
دوشنبه 31 فروردین 1388, 20:04 عصر
سلام دوستان
من یه برنامه ای با C# و sql 2000 نوشتم من از بانکم Backup می گیرم و هیچ مشکلی هم نداره این هم کدش:
private void button1_Click(object sender, EventArgs e)
{
string strFileName = string.Empty;
saveFileDialog1.DefaultExt = "BAK";
saveFileDialog1.FileName = "BackFile";
saveFileDialog1.Filter = @"SQL Backup Files (*.BAK) |*.BAK | All Files (*.*) |*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.Title = "Backup SQL File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = saveFileDialog1.FileName;
back(strFileName);
}
}
private void back(string strFileName)
{
try
{
string command = @"BACKUP DATABASE parsian TO DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=Computer1; initial catalog=parsian ;integrated security=true;");
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(command,oConnection);
oCommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("پشتيباني با موفقيت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("ERROR Occurd: " + ex.Message);
}
}
ام مشکل من در restore کردن آن می باشد یعنی برای بار اول که می خوام restore کنم این پیغام (پیوست کردم) را می دهد و بار بعدی یه پیغام دیگه و بار سوم می نویسه که کاربری از این بانک در حال استفاده می باشد و واردsql2000 هم می شود جلوی بانک مربوطه نوشته
(single user) این هم کد restore
private void button1_Click(object sender, EventArgs e)
{
string strFileName = string.Empty;
openFileDialog1.FileName = " ";
openFileDialog1.Filter = @"SQL Backup Files (*.BAK) |*.BAK | All Files (*.*) |*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Title = "Restor SQL File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = saveFileDialog1.FileName;
rest(strFileName);
}
}
private void rest(string strFileName)
{
try
{
string command = "ALTER DATABASE parsian SET SINGLE_USER with ROLLBACK IMMEDIATE " +
"use master " +
" RESTORE DATABASE parsian FROM DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=Computer1; initial catalog=parsian ;integrated security=true;");
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(command, oConnection);
oCommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("پشتيباني با موفقيت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("ERROR Occurd: " + ex.Message);
}
}
لینک تصویر error (http://mohammadpourabedin.googlepages.com/errorrestore.jpg)
با تشکر
من یه برنامه ای با C# و sql 2000 نوشتم من از بانکم Backup می گیرم و هیچ مشکلی هم نداره این هم کدش:
private void button1_Click(object sender, EventArgs e)
{
string strFileName = string.Empty;
saveFileDialog1.DefaultExt = "BAK";
saveFileDialog1.FileName = "BackFile";
saveFileDialog1.Filter = @"SQL Backup Files (*.BAK) |*.BAK | All Files (*.*) |*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.Title = "Backup SQL File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = saveFileDialog1.FileName;
back(strFileName);
}
}
private void back(string strFileName)
{
try
{
string command = @"BACKUP DATABASE parsian TO DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=Computer1; initial catalog=parsian ;integrated security=true;");
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(command,oConnection);
oCommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("پشتيباني با موفقيت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("ERROR Occurd: " + ex.Message);
}
}
ام مشکل من در restore کردن آن می باشد یعنی برای بار اول که می خوام restore کنم این پیغام (پیوست کردم) را می دهد و بار بعدی یه پیغام دیگه و بار سوم می نویسه که کاربری از این بانک در حال استفاده می باشد و واردsql2000 هم می شود جلوی بانک مربوطه نوشته
(single user) این هم کد restore
private void button1_Click(object sender, EventArgs e)
{
string strFileName = string.Empty;
openFileDialog1.FileName = " ";
openFileDialog1.Filter = @"SQL Backup Files (*.BAK) |*.BAK | All Files (*.*) |*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Title = "Restor SQL File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = saveFileDialog1.FileName;
rest(strFileName);
}
}
private void rest(string strFileName)
{
try
{
string command = "ALTER DATABASE parsian SET SINGLE_USER with ROLLBACK IMMEDIATE " +
"use master " +
" RESTORE DATABASE parsian FROM DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=Computer1; initial catalog=parsian ;integrated security=true;");
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(command, oConnection);
oCommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("پشتيباني با موفقيت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("ERROR Occurd: " + ex.Message);
}
}
لینک تصویر error (http://mohammadpourabedin.googlepages.com/errorrestore.jpg)
با تشکر