Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL2012 LocalDB: how to check in c# if it is currently installed?

Tags:

How to check in c# code if LocalDB currently installed? also, how to check if SQLNCLI11 presents in system?

like image 939
ZedZip Avatar asked Jul 24 '12 09:07

ZedZip


People also ask

Where is SQL database file location?

C:\Program Files\Microsoft SQL Server\MSSQL{nn}.


2 Answers

Check if LocalDB is installed, by looking for this registry key:

[HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\11.0] 

SQLNCLI11 - check the file version and presence of this file: C:\WINDOWS\system32\sqlncli.dll

like image 197
ErikEJ Avatar answered Sep 29 '22 00:09

ErikEJ


Here is a VB.NET example checking for LOCALDB

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 
like image 25
Scott Avatar answered Sep 28 '22 22:09

Scott