一、錯誤截圖
1、使用sa和windows用戶認證登錄都報錯,錯誤如下:
已成功與服務器建立連接,但是在登錄前的握手期間發生錯誤。 (provider: TCP Provider, error: 0 - 指定的網絡名不再可用。) (.Net SqlClient Data Provider)
二、分析過程
1、查看SQLServer服務,啟動狀態,沒有問題
2、Telnet數據庫端口,是通的,說明端口沒有問題
3、查看事件查看器,發現報錯如下:
Could not connect because the maximum number of '2' user connections has already been reached. The system administrator can use sp_configure to increase the maximum value. The connection has been closed. [CLIENT: <local machine>]
翻譯后:無法連接,因為已達到“2”用戶連接的最大數目。系統管理員可以使用sp_configure來增加最大值。連接已關閉。[客戶端:<local machine>]
三、解決辦法
1、使用sqlcmd登錄數據庫,並進入master數據庫
命令:
sqlcmd -E -A -S 127.0.0.1 use master go
2、打開高級選項
命令:
sp_configure 'show advanced options',1; go reconfigure; go sp_configure 'show advanced options'; go
3、設置用戶連接數為0(表示無限制)
命令:
sp_configure 'user connections','0'; go reconfigure; go sp_configure 'user connections'; go
4、重啟數據庫服務,再次登錄成功
注:命令行實際執行命令如下:
Microsoft Windows [版本 6.3.9600] (c) 2013 Microsoft Corporation。保留所有權利。 C:\Users\Administrator>sqlcmd -E -A -S 127.0.0.1 1> use master 2> go Changed database context to 'master'. 1> exec sp_configure 'show advanced option','1' 2> go Configuration option 'show advanced options' changed from 1 to 1. Run the RECONF IGURE statement to install. 1> reconfigure 2> go 1> exec sp_configure 'show advanced option' 2> go name minimum maximum config_value run_val ue ----------------------------------- ----------- ----------- ------------ ------- ---- show advanced options 0 1 1 1 1> exec sp_configure 'user connections' 2> go name minimum maximum config_value run_val ue ----------------------------------- ----------- ----------- ------------ ------- ---- user connections 0 32767 2 2 1> exec sp_configure 'user connections','0' 2> go Configuration option 'user connections' changed from 2 to 0. Run the RECONFIGURE statement to install. 1> exec sp_configure 'user connections' 2> go name minimum maximum config_value run_val ue ----------------------------------- ----------- ----------- ------------ ------- ---- user connections 0 32767 0 2 1> reconfigure 2> go 1>