PDA

View Full Version : سوال: مشکل در تعریف پارامتر



Smoke_1110
جمعه 02 اردیبهشت 1390, 23:44 عصر
سلام
من برای بکاپ این کد رو نوشتم ولی از این قسمت در کد که زیرش خط قرمز کشیدم ایراد میگیره که این ناشناخته است و تعریف نشده حالا باید این رو کجا تعریف کنم؟
try
{
string command = @"BACKUP DATABASE Mashmolin TO DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=.;InitialCatalog=Mashmolin;Integrated Security=True");
if (oConnection.State != ConnectionState.Open)
oConnection.Open();
oCommand = new SqlCommand(Sqlcommand, oConnection);
oCommand.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("پشتیبان گیری با موفقیت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("Error Occurd :" + ex.Message);
}
ارور هم اینه :
The name 'Sqlcommand' does not exist in the current context

میلاد قاضی پور
شنبه 03 اردیبهشت 1390, 02:30 صبح
به جای Sqlcommand بنویسید command . متغیر رشته ای شما اسمش command هست .

Smoke_1110
شنبه 03 اردیبهشت 1390, 12:23 عصر
الان درست شد ولی این ارور رو در هنگام بکاپ گیری میده :
cannot open backup device
BACKUP DATABASE is terminating abnormally

Smoke_1110
شنبه 03 اردیبهشت 1390, 20:53 عصر
کسی نمی دونه این ارور چه جوری حل میشه؟

arta.nasiri
شنبه 03 اردیبهشت 1390, 21:45 عصر
سلام

مقدار strFileName چیه ؟ باید پسوند bak. هم آخرش باشه.

اینو تست کن

try
{
string path = @"c:\\backup.bak";
string command = @"BACKUP DATABASE Mashmolin TO DISK='" + path + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=.;Initial Catalog=Mashmolin;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);
}

Smoke_1110
شنبه 03 اردیبهشت 1390, 23:39 عصر
سلام

مقدار strFileName چیه ؟ باید پسوند bak. هم آخرش باشه.

اینو تست کن

try
{
string path = @"c:\\backup.bak";
string command = @"BACKUP DATABASE Mashmolin TO DISK='" + path + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand oCommand = null;
SqlConnection oConnection = null;
oConnection = new SqlConnection("Data Source=.;Initial Catalog=Mashmolin;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);
}
همون ایراد رو گرفت