如果当前安装了LocalDB,如何检查c#代码?另外,如何检查SQLNCLI11是否存在于系统中?
答案 0 :(得分:16)
通过查找此注册表项来检查是否已安装LocalDB:
[HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\11.0]
SQLNCLI11 - 检查此文件的文件版本和存在:C:\WINDOWS\system32\sqlncli.dll
答案 1 :(得分:3)
我正在使用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;
}
答案 2 :(得分:2)
这是检查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
答案 3 :(得分:1)
我找到了这个包含SQLLocalDB的nuget包 有以下命令
SqlLocalDbApi.IsLocalDBInstalled()