[성현모] TRA Recovery 기능 수정
This commit is contained in:
@ -50,54 +50,65 @@ namespace SystemX.Product.CP.RecoveryTool
|
||||
}
|
||||
textMdf.Text = mdfFile; //mdf
|
||||
textLdf.Text = ldfFile; //ldf
|
||||
}
|
||||
textRecoveryName.Text = Path.GetFileNameWithoutExtension(textMdf.Text);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAttach_Click(object sender, EventArgs e)
|
||||
{
|
||||
string error = "success";
|
||||
|
||||
if (File.Exists(mdfFile) == true)
|
||||
ledMdf.BackColor = Color.Lime;
|
||||
else
|
||||
{
|
||||
ledMdf.BackColor = Color.Red;
|
||||
error = "Invalid FIle";
|
||||
}
|
||||
DialogResult result = MessageBox.Show(
|
||||
$"Attach DB Name: '{textRecoveryName.Text}_Recovery' 연결 하시겠습니까?", // 메시지 내용
|
||||
"Attach DB", // 타이틀
|
||||
MessageBoxButtons.YesNo, // 버튼 옵션
|
||||
MessageBoxIcon.Question // 아이콘 (선택 사항)
|
||||
);
|
||||
|
||||
if (File.Exists(ldfFile) == true)
|
||||
ledLdf.BackColor = Color.Lime;
|
||||
else
|
||||
if(result == DialogResult.Yes)
|
||||
{
|
||||
ledLdf.BackColor = Color.Red;
|
||||
error = "Invalid FIle";
|
||||
}
|
||||
|
||||
recoveryName = textRecoveryName.Text;
|
||||
if (string.IsNullOrEmpty(recoveryName) == false)
|
||||
ledLdf.BackColor = Color.Lime;
|
||||
else
|
||||
{
|
||||
ledLdf.BackColor = Color.Red;
|
||||
error = "Invalid RecoveryName";
|
||||
}
|
||||
|
||||
lbAttachResult.Text = error;
|
||||
if (error == "success")
|
||||
{
|
||||
string attachError = Attach(mdfFile, ldfFile, recoveryName);
|
||||
if (string.IsNullOrEmpty(attachError) == false)
|
||||
if (File.Exists(mdfFile) == true)
|
||||
ledMdf.BackColor = Color.Lime;
|
||||
else
|
||||
{
|
||||
lbAttachResult.ForeColor = Color.Red;
|
||||
lbAttachResult.Text = attachError;
|
||||
ledMdf.BackColor = Color.Red;
|
||||
error = "Invalid Mdf File";
|
||||
}
|
||||
|
||||
if (File.Exists(ldfFile) == true)
|
||||
ledLdf.BackColor = Color.Lime;
|
||||
else
|
||||
{
|
||||
ledLdf.BackColor = Color.Red;
|
||||
error = "Invalid Ldf File";
|
||||
}
|
||||
|
||||
recoveryName = textRecoveryName.Text;
|
||||
if (string.IsNullOrEmpty(recoveryName) == false)
|
||||
ledLdf.BackColor = Color.Lime;
|
||||
else
|
||||
{
|
||||
ledLdf.BackColor = Color.Red;
|
||||
error = "Invalid RecoveryName";
|
||||
}
|
||||
|
||||
lbAttachResult.Text = error;
|
||||
if (error == "success")
|
||||
{
|
||||
string attachError = Attach(mdfFile, ldfFile, recoveryName);
|
||||
if (string.IsNullOrEmpty(attachError) == false)
|
||||
{
|
||||
lbAttachResult.ForeColor = Color.Red;
|
||||
lbAttachResult.Text = attachError;
|
||||
}
|
||||
else
|
||||
lbAttachResult.ForeColor = Color.Lime;
|
||||
}
|
||||
else
|
||||
lbAttachResult.ForeColor = Color.Lime;
|
||||
}
|
||||
else
|
||||
lbAttachResult.ForeColor = Color.Red;
|
||||
|
||||
SelectDBList();
|
||||
lbAttachResult.ForeColor = Color.Red;
|
||||
|
||||
SelectDBList();
|
||||
}
|
||||
}
|
||||
|
||||
private string Attach(string mdfFile, string ldfFile, string attachName)
|
||||
@ -105,7 +116,7 @@ namespace SystemX.Product.CP.RecoveryTool
|
||||
string error = string.Empty;
|
||||
|
||||
// 프로세스 설정
|
||||
string command = $" -S localhost -U alis -P Kefico!@34 -Q \"CREATE DATABASE {attachName} ON (FILENAME = '{mdfFile}'), (FILENAME = '{ldfFile}') FOR ATTACH;\"";
|
||||
string command = $" -S localhost -U alis -P Kefico!@34 -Q \"CREATE DATABASE {attachName}_Recovery ON (FILENAME = '{mdfFile}'), (FILENAME = '{ldfFile}') FOR ATTACH;\"";
|
||||
Console.WriteLine(command);
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
@ -182,7 +193,7 @@ namespace SystemX.Product.CP.RecoveryTool
|
||||
var connMain = new SqlConnection("server=127.0.0.1,1433;uid=alis;password=Kefico!@34;");
|
||||
connMain.Open();
|
||||
|
||||
SqlCommand SQLCmd = new SqlCommand("select name from sys.databases with(nolock) where owner_sid != 0x01;", connMain);
|
||||
SqlCommand SQLCmd = new SqlCommand("select name from sys.databases with(nolock) where owner_sid != 0x01 and name like '%Recovery%';", connMain);
|
||||
SQLCmd.CommandType = CommandType.Text;
|
||||
DbDataReader dtReader = SQLCmd.ExecuteReader();
|
||||
|
||||
@ -203,9 +214,25 @@ namespace SystemX.Product.CP.RecoveryTool
|
||||
if (e.ColumnIndex == 2)
|
||||
{
|
||||
var dbName = gridDB.Rows[e.RowIndex].Cells[1].Value.ToString();
|
||||
Detach(dbName);
|
||||
SelectDBList();
|
||||
|
||||
DialogResult result = MessageBox.Show(
|
||||
$"Attach DB Name: '{dbName}' 연결을 삭제 하시겠습니까?", // 메시지 내용
|
||||
"Detach DB", // 타이틀
|
||||
MessageBoxButtons.YesNo, // 버튼 옵션
|
||||
MessageBoxIcon.Question // 아이콘 (선택 사항)
|
||||
);
|
||||
|
||||
if(result == DialogResult.Yes)
|
||||
{
|
||||
Detach(dbName);
|
||||
SelectDBList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectDBList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user