응용 프로그램을 업그레이드하는 데 사용되는 WinForms 응용 프로그램을 통해 SQL Server 2005 Express에서 SQL Server 2008 R2 Express 로의 업그레이드를 자동화하고 있습니다. 응용 프로그램은 800 개 이상의 위치에 배포되므로 수동 단계가 필요하지 않습니다.C# WinForms 응용 프로그램에서 SQL Server 자동 업그레이드가 성공했는지 확인하는 방법
다음 코드는 대부분 업그레이드를 수행하기 위해 작성된 코드입니다. SQL Server 설치 프로그램이 성공적으로 완료되었는지 확인하는 가장 좋은 방법은 무엇입니까? 프로세스의 종료 코드 0을 찾아야합니까? 그게 충분히 좋은가요? 즉, 업그레이드에 문제가 발생하여 롤백 된 경우 코드 0으로 종료 될 수 있습니까 (테스트 할 것이지만 오류를 시뮬레이트하는 가장 좋은 방법을 모르는 경우)?
SQL Server Installer에서 오류가 발생하면 제대로 처리 할 수 있도록 C# 응용 프로그램에서 업그레이드가 성공했는지 확인할 수있는 다른 방법이 있습니까?
try
{
//First, find the version of the currently installed SQL Server Instance
string sqlString = "SELECT SUBSTRING(CONVERT(VARCHAR, SERVERPROPERTY('productversion')), 0, 5)";
string sqlInstanceVersion = string.Empty;
using (DbCommand cmd = _database.GetSqlStringCommand(sqlString))
{
sqlInstanceVersion = cmd.ExecuteScalar().ToString();
}
if (sqlInstanceVersion.Equals(String.Empty))
{
//TODO throw an exception or do something else
}
//11.00 = SQL2012, 10.50 = SQL2008R2, 10.00 = SQL2008, 9.00 = SQL2005, 8.00 = SQL2000
switch (sqlInstanceVersion)
{
case "11.00":
case "10.50":
case "10.00":
//Log that the version is already up to date and return
return;
case "9.00":
case "8.00":
//We are on SQL 2000 or 2005, so continue with upgrade to 2008R2
break;
default:
//TODO throw an exception for unsupported SQL Server version
break;
}
string upgradeArgumentString = "/Q /ACTION=upgrade /INSTANCENAME={0} /ENU /IACCEPTSQLSERVERLICENSETERMS";
string instanceName = "YourInstanceNameHere";
string installerFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\SQLEXPR_x86_ENU.exe";
if (!File.Exists(installerFilePath))
{
throw new FileNotFoundException(string.Format("Unable to find installer file: {0}", installerFilePath));
}
Process process = new Process
{
StartInfo = { FileName = installerFilePath, Arguments = String.Format(upgradeArgumentString, instanceName), UseShellExecute = false }
};
process.Start();
if (process.WaitForExit(SQLSERVER_UPGRADE_TIMEOUT))
{
//Do something here when the process completes within timeout.
//What should I do here to determine if the SQL Server Installer completed successfully? Look at just the exit code?
}
else
{
//The process exceeded timeout. Do something about it; like throw exception, or whatever
}
}
catch(Exception ex)
{
//Handle your exceptions here
}
전후 버전을 보면 충분할 수도 있습니다. SQL 업그레이드가 완료되지 않은 경우 발생한 일에 대한 Process 개체의 세부 정보를 얻을 수있는 방법이 있습니까? 나는 버전이 업그레이드 후에 변경되지 않았다면 사용자에게 설치 로그를 보도록 지시 할 수 있습니까? – Jim
잘 모르겠지만 전형적인 설치 오류 메시지가 슬픈 상태 일 때 프로그램 적으로 의미있는 이유를 추출 할 수 없을 것입니다. 설치 로그는 좋은 생각입니다. – usr