【发布时间】:2012-07-24 09:51:11
【问题描述】:
如果当前安装了 LocalDB,如何检查 c# 代码?另外,如何检查系统中是否存在SQLNCLI11?
【问题讨论】:
如果当前安装了 LocalDB,如何检查 c# 代码?另外,如何检查系统中是否存在SQLNCLI11?
【问题讨论】:
通过查找此注册表项检查是否安装了 LocalDB:
[HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\11.0]
SQLNCLI11 - 检查文件版本和此文件是否存在:C:\WINDOWS\system32\sqlncli.dll
【讨论】:
这是一个检查 LOCALDB 的 VB.NET 示例
Public Shared Function CheckLocalDBExists() As Boolean
Dim s As String = ""
Dim reg As RegistryKey
Dim rtn As Boolean = False
reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\12.0", True)
Try
s = reg.GetValue("ParentInstance", "").ToString
reg.Close()
Catch ex As Exception
s = Nothing
End Try
'MessageBox.Show(s)
If s = "MSSQL12E.LOCALDB" Then
rtn = True
End If
Return rtn
End Function
【讨论】:
我正在使用the answer to this question
检查sqllocaldb.exe是否存在
像这样:
public static bool IsLocalDBInstalled()
{
return ExistsOnPath("SqlLocalDB.exe"); ;
}
public static bool ExistsOnPath(string fileName)
{
return GetFullPath(fileName) != null;
}
public static string GetFullPath(string fileName)
{
if (File.Exists(fileName))
return Path.GetFullPath(fileName);
var values = Environment.GetEnvironmentVariable("PATH");
foreach (var path in values.Split(';'))
{
var fullPath = Path.Combine(path, fileName);
if (File.Exists(fullPath))
return fullPath;
}
return null;
}
【讨论】:
我发现了这个 nuget 包,它结束了使用 SQLLocalDB 有以下命令
SqlLocalDbApi.IsLocalDBInstalled()
【讨论】: