我在系统中安装了两个版本的SQL Server Express LocalDB (2012, 2014)。
如何查找所有现有的LocalDB
实例名称?
我在答案部分找到了使用命令行的方法来完成这个任务。
是否有更好、更易用的方法来完成此操作?
我在系统中安装了两个版本的SQL Server Express LocalDB (2012, 2014)。
如何查找所有现有的LocalDB
实例名称?
我在答案部分找到了使用命令行的方法来完成这个任务。
是否有更好、更易用的方法来完成此操作?
我发现了需要在命令行上运行的SqlLocalDB实用程序。
可以在
C:\Program Files\Microsoft SQL Server\110\Tools\Binn
或者C:\Program Files\Microsoft SQL Server\120\Tools\Binn
要获取所有现有的 LocalDB
实例名称,请使用:
SqlLocalDB.exe i
info|i
Lists all existing LocalDB instances owned by the current user
and all shared LocalDB instances.
获取有关特定 LocalDB
实例的详细信息:
SqlLocalDB.exe i "MSSQLLocalDB"
info|i "instance name"
Prints the information about the specified LocalDB instance.
localdb实例
,可以查看vineel的答案!localdb 实例
的所有 数据库
(可能无法在 SSMS2019 中使用),请参考以下步骤:(LocalDB)\MSSQLLocalDB
。
现在,您将看到所有 LocalDB 实例。这是我使用的方法,从命令行获取所有实例 -
internal static List<string> GetLocalDBInstances()
{
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C sqllocaldb info";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string sOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
//If LocalDb is not installed then it will return that 'sqllocaldb' is not recognized as an internal or external command operable program or batch file.
if (sOutput == null || sOutput.Trim().Length == 0 || sOutput.Contains("not recognized"))
return null;
string[] instances = sOutput.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
List<string> lstInstances = new List<string>();
foreach (var item in instances)
{
if (item.Trim().Length > 0)
lstInstances.Add(item);
}
return lstInstances;
}
MSSQLLocalDB
实例(并列出了数据库)。这不会列出所有实例的名称! - Ronald