我正在尝试查询以下注册表项值:
HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\SharedMemoryOn HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib\ProtocolOrder
但是,根据我运行程序的机器,查询将返回null。当我在本地机器上调试并检查ValueCount的值时:
HKLM\SOFTWARE\Microsoft\MSSQLServer\Client HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib
计数为0,OpenSubKey返回null。
我是本地管理员组中的域管理员,并已将以下内容添加到我的app.manifest中:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />知道为什么吗?
private static void ValidateSqlClientSettings()
{
Console.WriteLine("\r\n/////////////// LOCAL SQL CLIENT PROTOCOLS ////////////////");
RegistryKey keyHKLM = Registry.LocalMachine;
///TODO: nullreferenceexception - connect to remote machine and find out why
RegistryKey sqlClientKey = keyHKLM.OpenSubKey(@"SOFTWARE\Microsoft\MSSQLServer\Client");
if (sqlClientKey == null)
{
WriteLine2Console(@"WARNING: unable to read registry key '{0}\SOFTWARE\Microsoft\MSSQLServer\Client'", ConsoleColor.Yellow);
}
var cliKeyNames = from k in sqlClientKey.GetSubKeyNames()
where k == "SuperSocketNetLib"
select k;
///TODO: find out why these values are always missing (even if I can see them in regedit)
Console.Write("Shared Memory Disabled (cliconfg): ");
if (Convert.ToBoolean(sqlClientKey.GetValue("SharedMemoryOn")))
WriteLine2Console("FAILED", ConsoleColor.Red);
else if(sqlClientKey.GetValue("SharedMemoryOn") == null)
WriteLine2Console(String.Format("WARNING - unable to read '{0}\\SharedMemoryOn'", sqlClientKey.Name), ConsoleColor.Yellow);
else
WriteLine2Console("PASS", ConsoleColor.Green);
Console.Write("Client Protocol Order (cliconfg - tcp first): ");
foreach (string cliKey in cliKeyNames)
{
RegistryKey subKey = sqlClientKey.OpenSubKey(cliKey);
object order = subKey.GetValue("ProtocolOrder");
if (order != null && order.ToString().StartsWith("tcp") == false)
{
WriteLine2Console("FAILED", ConsoleColor.Red);
}
else if (order == null)
{
WriteLine2Console(String.Format("WARNING - unable to read '{0}\\ProtocolOrder'", subKey.Name), ConsoleColor.Yellow);
}
else
{
WriteLine2Console("PASS", ConsoleColor.Green);
}
subKey.Close();
}
sqlClientKey.Close();
keyHKLM.Close();
}发布于 2010-05-22 07:50:20
您应该注意的另一个因素是应用程序位数。
在Windows上,当您(在代码中)指定“x64 \MSSQLServer\Client”时,您的x86构建将在(在regedit中) "SOFTWARE\WOW6432Node\Microsoft\MSSQLServer\Client",下查找注册表项。
这是注册表项的WOW64重定向。
由于Visual Studio2010默认情况下在x86模式下创建exe,因此您应该注意本技巧。
发布于 2010-05-22 04:28:09
尝试将sqlclientkey更改为以下内容:
RegistryKey sqlClientKey = keyHKLM.OpenSubKey(@"SOFTWARE\\Microsoft\\MSSQLServer\\Client"); https://stackoverflow.com/questions/2885097
复制相似问题