22

我想在我的Windows 7 x64機器上建立一個SQL Server 2012 LocalDB(RTM,x64)共享實例,我似乎無法連接到共享實例。我正在使用管理員命令提示符進行所有設置。下面是我如何創建實例:爲什麼我無法連接到SQL Server 2012 LocalDB共享實例?

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". 

仍在尋找好。在這一點上,我的信息的命令得到:同時使用管理員或非管理員命令提示符

.\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實例。除非沒有「MyInstance」,否則非admin用戶的info命令會產生與上述相同的結果,因爲它是admin用戶擁有的命名實例。下面的命令(其中工程管理員用戶/實例所有者):

sqllocaldb info ".\MySharedInstance" 

也導致錯誤:

Windows API call "FileTimeToSystemTime" returned error code: -2147024809. 

所以,問題是,爲什麼不能我非管理員用戶連接到我的共享實例?這似乎打敗了共享實例的全部目的。當我嘗試查詢共享實例時,「sqllocaldb info」命令有什麼問題會引發錯誤?

+0

你說的是一個非管理員的Windows用戶連接?所以你已經註銷並以不同的用戶身份登錄?或者是用戶試圖從不同的機器連接? – 2012-04-18 17:37:56

+0

以不同的用戶身份登出並重新登錄。我不需要從不同的機器連接。 – 2012-04-18 17:55:53

+0

您確定實例在註銷事件之後仍然存在嗎?如果您以管理員用戶身份註銷並重新登錄,會發生什麼情況?我懷疑你會遇到同樣的問題。 – 2012-04-18 18:00:11

回答

24

ANOTHER編輯

科裏,如果你有安裝了SQL Server(例如2008年)以前的版本,那就是sqlcmd版本所使用。爲了連接到LocalDb,您需要使用sqlcmd的SQL Server 2012版本。所以,你的用戶在你的指令必須確保他們通過運行使用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(一旦你授予足夠的權限),希望剋日什托夫·將有更多信息其他項目。


關於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.

+3

這解決了我的問題! – Andy 2013-05-03 16:12:35

+0

對我也是 – Gomes 2013-09-26 10:01:42

-4

問題是你需要引用的數據庫名稱:

sqlcmd -S "(localdb)\.\MySharedInstance" 
+1

我不認爲這是答案;一旦我使用正確版本的sqlcmd(Sql Server 2012附帶的版本),我就不需要引用它。 – Andy 2013-05-03 16:13:12

6

由於原來的建議後,該WASN沒有預期的那麼直接,但我最終能夠通過命名管道進行連接。

Connecting to a LocalDB instance via named pipe

+0

奇怪的是,我與默認的MSSQLLocalDB實例有相同的問題,並且通過實例管道名稱進行連接(刪除之前存在的C:\ Users \ \中的數據庫MDF和LDF文件之後)。 – 2017-01-19 17:12:12

1

這個答案承擔,刪除實例確定。
ie:你所有的數據都將消失,那沒關係。

升級我的SSMS後,我遇到了同樣的問題。

sqllocaldb i 
.\MyCustomInstance 

sqllocaldb d 
LocalDb instance ".\MyCustomInstance" does not exist! 

sqllocaldb i .\MyCustomInstance 
Windows API call "FileTimeToSystemTime" returned error code: -2147024809. 

爲了擺脫違規的情況下,我不得不創建另一個MyCustomInstance我的猜測將覆蓋哪些已經存在的,現在你可以刪除它

sqllocaldb c MyCustomInstance 
LocalDB instance "MyCustomInstance" created with version 11.0. 
sqllocaldb d .\MyCustomInstance 
LocalDB instance ".\Octopus" deleted. 

然後,啓動實例,並分享它。 必須先開始實例。

sqllocaldb s MyCustomInstance 
LocalDB instance "MyCustomInstance" started. 
sqllocaldb h MyCustomInstance MyCustomInstance 
Private LocalDB instance "MyCustomInstance" shared with the shared name: "MyCustomInstance". 

現在,當你需要連接,您(localdb)\.\MyCustomInstance