JDBC 連Sql Server 接數據庫--The TCP/IP connection to the host localhost, port 1433 has failed


原文:https://blog.csdn.net/qq_39241986/article/details/80848855

 

這樣的錯誤,你有遇到過嗎?

The TCP/IP connection to the host localhost, port 1433 has failed.
  • 1

這里寫圖片描述

com.microsoft.sqlserver.jdbc.SQLServerException: 
The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 
Verify the connection properties.
Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
  • 1
  • 2
  • 3
  • 4
  • 5

解決方法:

1.選中此電腦–>右鍵管理–>計算機管理–>服務和應用程序 
   (1)先查看 sql server 服務是否已經開啟 
到–>SQL Server 配置管理器–>SQL Server 服務,確保本地Sql Server 服務已經開啟。 
這里寫圖片描述 
   (2)再查看 sql server 網絡配置 
到–>SQL Server 配置管理器–>SQL Server 網絡配置,確保Named PipesTCP/IP 協議為已啟用狀態。 
這里寫圖片描述 
2.我們再次運行程序,可能會出現還是連接不成功的現象,繼續解決問題: 
   還是看 sql server 網絡配置 
到–>SQL Server 配置管理器–>SQL Server 網絡配置,Named PipesTCP/IP 協議為已啟用狀態,選中TCP/IP右鍵–>屬性–>IP地址,往下拉滾動條,查看IPALLTCP端口是否為1433,不是,則改為1433。 
這里寫圖片描述 
最后,重啟SQL Server服務,然后再運行程序,成功,舒服啦 ! 
這里寫圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM