gpt4 book ai didi

sql-server - 为什么我无法连接到 SQL Server 2012 LocalDB 共享实例?

转载 作者:行者123 更新时间:2023-12-03 07:31:49 25 4
gpt4 key购买 nike

我正在尝试在我的 Windows 7 x64 机器上设置一个 SQL Server 2012 LocalDB (RTM, x64) 共享实例,但我似乎无法连接到共享实例。我正在使用管理员命令提示符进行所有设置。这是我创建实例的方式:

sqllocaldb create MyInstance

这产生了响应:
LocalDB instance "MyInstance" created with version 11.0.

到现在为止还挺好。现在我分享一下实例:
sqllocaldb share "MyInstance" "MySharedInstance"

结果是:
Private LocalDB instance "MyInstance" shared with the shared name: "MySharedInstance".

看起来还是不错的。此时,我的 info 命令产生:
.\MySharedInstance
MyInstance
v11.0

使用管理员或非管理员命令提示符从所有者帐户(管理员)连接到实例似乎工作正常。然而,当我以普通用户(不是 Windows 管理员)登录并尝试连接时,事情就偏离了轨道:
sqlcmd -S (localdb)\.\MySharedInstance

结果是:
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Named Pipes Provider: Could not open a connection to SQL Server [2]. .
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login timeout expired.
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

使用“-l”开关增加登录超时没有帮助。我可以连接到未共享的默认 v11.0 实例。非管理员用户的 info 命令产生与上面相同的结果,除了没有“MyInstance”,因为它是管理员用户拥有的命名实例。以下命令(适用于管理员用户/实例所有者):
sqllocaldb info ".\MySharedInstance"

也会导致错误:
Windows API call "FileTimeToSystemTime" returned error code: -2147024809.

所以问题是为什么我的非管理员用户不能连接到我的共享实例?这似乎违背了共享实例的全部目的。当我尝试查询共享实例时,“sqllocaldb info”命令抛出错误是怎么回事?

最佳答案

另一个编辑

Cory,如果您安装了以前版本的 SQL Server(例如 2008),那就是 sqlcmd 的版本您正在使用。为了连接到 LocalDb,您需要使用 SQL Server 2012 版本的 sqlcmd .因此,您对用户的说明必须通过运行以下命令来确保他们使用 SQL Server 2012 版本:
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd -S "(localdb)\.\InstanceName"
这对我有用。我没有验证的是sqlcmd的这个路径和版本是否可供仅安装 sqllocaldb.msi 的用户使用。抱歉,我没有任何未安装 SQL Server 2012(或仅安装以前版本)的裸机来彻底尝试一下。但是如果明确调用 sqlcmd 的 110 版本,请告诉我诀窍。

我认为您也可以指示用户更改他们的系统变量,以便 110 版本首先出现(恕我直言应该是自动的)。
FileTimeToSystemTime已被 Krzysztof 的一位同事确认为错误。因此,我所知道的非所有者通过 sqllocaldb 连接仍然没有解决方法。 .但我已经证明了 SSMS 和 sqlcmd可以开始工作,所以我希望这能让你更接近运行。

编辑

您需要将任何非所有者用户添加到实例中,例如CREATE LOGIN [MyDomain\OtherUser] FROM WINDOWS;以及任何适当的权限。在我的测试登录失败并生成错误的错误消息(“FileTimeToSystemTime”错误消息是一个错误)。您还需要GRANT CONNECT .完成此操作后,您将能够使用具有此连接的 Management Studio 从第二个用户进行连接(我尝试过的唯一一个):

(localdb)\.\MySharedInstance

但来自 sqlcmd ,无论我如何尝试连接,我仍然收到错误消息:
sqlcmd -S "(localdb)\.\MySharedInstance"
sqlcmd -S ".\MySharedInstance"
sqlcmd -S "(localdb)\MySharedInstance"
sqlcmd -S "GREENHORNET\MySharedInstance"
sqlcmd -S ".\LOCALDB#SH04FF8A"
sqlcmd -S "GREENHORNET\LOCALDB#SH04FF8A"

所有产量:

HResult 0xFFFFFFFF, Level 16, State 1 SQL Server Network Interfaces:

Error Locating Server/Instance Specified [xFFFFFFFF].

Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired.



尽管我已验证该实例已设置为接受远程连接。所以还有一些其他的箍 sqlcmd一定要通过。

关于 sqllocaldb exe,这如何遵循任何逻辑?我可以通过 info 看到实例在那里,当我尝试停止它时,我收到一条正确的错误消息,当我尝试启动它时,我收到一条消息,它 [已经] 启动,但我无法连接到它?

enter image description here

所以除非你需要 sqlcmd访问,在短期内,我会让次要用户使用 SSMS 做他们的事情(一旦您授予了足够的权限),希望 Krzysztof 将获得有关其他项目的更多信息。

关于 4.0.2 更新,来自 http://connect.microsoft.com/SQLServer/feedback/details/723737/smo-cant-connect-to-localdb-instances :

We made an explicit decision not to include .NET Framework 4.0.2 in LocalDB installer. Installing the .NET Framework update would increase the size of the LocalDB installer and cause a likely reboot. Since LocalDB is built to be independent of the .NET, we didn’t think we should take this cost for every LocalDB installation. Future .NET versions (including .NET 4.5, now in CTP) will support LocalDB out of the box. Some developers may also want to opt in for ODBC, PHP Driver/PDO, and probably JDBC in the future. Those developers will not be interested in updating .NET.

关于sql-server - 为什么我无法连接到 SQL Server 2012 LocalDB 共享实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10214688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com