问题
In SQL Express bootstrapper there is a file called SqlExpressChk.exe used to check the version of the installed SQL Express.
Unfortunately I've read that this file is looking for instance name SQLEXPRESS. Does anybody know how to force SqlExpressChk to look for another instance name ? I don't install SQL Server with default instance name.
Thanks.
回答1:
There isn't a way. SqlExpressChk.exe is limited to only the default instance name, SQLEXPRESS. It won't detect other named instances as documented on MSDN.
You can check for instances in a variety of other ways however.
There are a whole variety of ways listed in answers to this related SO question.
There is PowerShell as documented in this simple talk article:
# SQLVer.ps1
# usage: ./SQLVer.ps1
# Check SQL version
foreach ($svr in get-content "C:\data\AllServers.txt")
{
$con = "server=$svr;database=master;Integrated Security=sspi"
$cmd = "SELECT SERVERPROPERTY('ProductVersion') AS Version, SERVERPROPERTY('ProductLevel') as SP"
$da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
$dt = new-object System.Data.DataTable
$da.fill($dt) | out-null
$svr
$dt | Format-Table -autosize
}
There is also WMI as documented in this MSDN article:
try
{
// Run a WQL query to return information about SKUNAME and SPLEVEL about installed instances
// of the SQL Engine.
ManagementObjectSearcher getSqlExpress =
new ManagementObjectSearcher("root\\Microsoft\\SqlServer\\ComputerManagement",
"select * from SqlServiceAdvancedProperty where SQLServiceType = 1 and
ServiceName = '" + instance + "' and (PropertyName = 'SKUNAME' or
PropertyName = 'SPLEVEL')");
// If nothing is returned, SQL Express isn't installed.
if (getSqlExpress.Get().Count==0)
{
return false;
}
}
catch (ManagementException e)
{
Console.WriteLine("Error: " + e.ErrorCode + ", " + e.Message);
return false;
}
来源:https://stackoverflow.com/questions/10309861/how-to-force-sqlexpresschk-exe-from-bootstrapper-to-check-for-other-instance-tha