One way to check whether SQL Server Local DB is installed is through the record HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions
already quoted in @daniloloko’s reply, however, it is necessary to specify for the RegistryKey
if the system is x86
or x64
.
We can do this through the property Is64BitOperatingSystem
class Environment to determine whether the system is 64bit or 32bit, then specify which display of the record should be used RegistryView.Registry64;
or RegistryView.Registry32;
in the object RegistryView
.
Follow the software that checks whether SQL Server Local BD is installed:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;
namespace SQLServerLocalDBInstalledExemplo
{
class Program
{
static void Main(string[] args)
{
RegistryView registryViewArchitecture;
if (Environment.Is64BitOperatingSystem)
registryViewArchitecture = RegistryView.Registry64;
else
registryViewArchitecture = RegistryView.Registry32;
using (RegistryKey registryKeyLocalMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryViewArchitecture))
{
RegistryKey registryKey = registryKeyLocalMachine.OpenSubKey(@"HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions", false);
if (registryKey != null)
Console.WriteLine("SQL Server Local DB instalado.");
else
Console.WriteLine("SQL Server Local DB não esta instalado.");
}
Console.ReadKey();
}
}
}
To manipulate the record you need to add the namespace Microsoft.Win32, see also that it was necessary to use the method OpenBaseKey
class RegistryKey
, this method allows you to open a new RegistryKey
representing the requested key on the local machine with the display mode specified on the object registryViewArchitecture
.
Sources:
Check if SQL Server is installed on a machine through C#
SQL2012 Localdb: how to check in c# if it is Currently installed?
Try to check through this record:
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\11.0
– gato
The answer to your question has already been given , but if it is possible to migrate to localdb 2016 you do not need anything installed to run !
– John Diego
That is, there is no need to install SQL Server for anyone who runs and is not installed?
– Chirag Geiantilal