1

从程序开发人员的角度来看,将 PowerShell 与“Microsoft SQL Server 2012 LocalDB”结合起来与 SQL Server 数据库引擎进行交互是非常有吸引力的。从 PowerShell 连接到 LocalDB 实例、使用数据库对象和执行 Transact-SQL 语句都可以正常工作。在此组合中添加“Microsoft SQL Server 2012 共享管理对象”(SMO) 时也是如此。

我无法通过 PowerShell SQLPS 模块(“Microsoft Windows PowerShell Extensions for Microsoft SQL Server 2012 Feature Pack”)浏览 LocalDB 实例。后者尝试获取 SQL Server 服务信息,而 LocalDB 不创建任何数据库服务。

然而,是否有一种方法可以使 SQLPS 模块可以看到 LocalDB 实例?

4

1 回答 1

0

I don't think there's any way to extend SQLPS and/or SMO to include LocalDB instances on the list of SQL Server instances. Currently SQLPS and SMO don't understand LocalDB instance model, just like (I think) it didn't understand User Instances of SQL Server Express before. Also mixing regular and LocalDB instances could be confusing to end users. LocalDB instances are per-user and only visible by the user who owns them, so different users would get a different list on the same machine. Regular SQL Server instances are installed per-machine, and all users see the same list.

I bet you could write your own PowerShell plugin or module. All you need to do is to call LocalDBGetInstances and LocalDBGetInstanceInfo functions from LocaLDB API (available through C/C++) plus the existing SQLPS or SMO for the regular SQL Server instances. I'm not sure how you distribute such plugin though.

于 2012-11-03T20:06:36.020 回答