vin*_*eel 34 sql-server sql-server-2008 sql-server-2012
我的系统中安装了两个版本(2012,2014)的SQL Server Express LocalDB.
如何查找所有现有LocalDB实例名称?
我找到了一种使用命令行的方法,如答案部分所述.
有没有更好,更简单的方法呢?
vin*_*eel 53
我找到了需要在命令行上运行的SqlLocalDB实用程序.
可以在中找到SqlLocalDB
C:\Program Files\Microsoft SQL Server\110\Tools\Binn
Run Code Online (Sandbox Code Playgroud)
要么
C:\Program Files\Microsoft SQL Server\120\Tools\Binn
Run Code Online (Sandbox Code Playgroud)
要获取所有现有LocalDB实例名称,请使用:
SqlLocalDB.exe i
info|i
Lists all existing LocalDB instances owned by the current user
and all shared LocalDB instances.
Run Code Online (Sandbox Code Playgroud)
要获取有关特定LocalDB实例的详细信息:
SqlLocalDB.exe i "MSSQLLocalDB"
info|i "instance name"
Prints the information about the specified LocalDB instance.
Run Code Online (Sandbox Code Playgroud)
Leg*_*nds 13
如果您更喜欢UI方式
只需打开您的SSMS并连接即可(LocalDB)\MSSQLLocalDB.
现在您将看到所有的LocalDB实例.
这至少适用于SS2016,不能保证早期版本.
小智 6
这是我用来从命令行获取所有实例的方法 -
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;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
在Visual Studio 2019 服务器资源管理器(或SQL Server 对象资源管理器按钮)中,单击“添加 SQL Server ”按钮
并展开“本地”选项卡以查看它找到的当前正在运行的本地SQL Server服务的列表。仅当您连接到所选服务器时,它才会在SQL Server 对象资源管理器中列出: