0
//我在看起來像了聲明標量變量@@ SA_CONSOLE_HOSTNAME
//插入到表名(主機,實例)值(@SA_CONSOLE_HOSTNAME,值)查詢,在表名我已經創建的列主機和主機將作爲我的本地機器名稱的實例。我不想每次代碼在不同的系統 因此創造了一個可變的,並且機器名稱,將其運行時輸入計算機名,
//我創建了一個存根並通過計算機名給它
String scriptAndStub;
scriptAndStub =
"DECLARE @SA_CONSOLE_HOSTNAME VARCHAR(256)\n" + \\ creating a variable
"SET @SA_CONSOLE_HOSTNAME = @[email protected]\n";
scriptAndStub += script;
executeScript.CommandText = scriptAndStub;
executeScript.Parameters.AddWithValue("@[email protected]", Environment.MachineName); \\passing machine name
//當我點擊文本框檢查語法按鈕,其產生錯誤
private void btnSyntaxCheck_Click(object sender, EventArgs e)
{
try
{
tsStatus.Text = "Checking Syntax...";
LogMessage(DA_Base.Constants.ERROR_LEVEL_DEBUG, "SQLScripting::SyntaxCheck", "Query: " + rtbScript.Text);
using (SqlCommand myCommand = new SqlCommand(string.Empty, Connection))
{
foreach (string script in Regex.Split(rtbScript.Text, "^GO\r?$", RegexOptions.Multiline | RegexOptions.IgnoreCase))
{
if (!String.IsNullOrEmpty(script))
{
myCommand.CommandText = "SET PARSEONLY ON\n" + script;
myCommand.ExecuteNonQuery();
}
}
}
tsStatus.Text = "Checking Syntax Complete. No errors reported.";
}
catch (Exception exc) \\error has been caught here....
{
tsStatus.Text = exc.Message;
MessageBox.Show(exc.Message, "SQL Syntax Check");
}
}
}
}