SQL Server报错com.microsoft.sqlserver.jdbc.SQLServerException:用户'sa'登录失败、端口1433连接到localhost的TCP/IP连接失败
最新推荐文章于 2023-08-03 18:03:15 发布
最新推荐文章于 2023-08-03 18:03:15 发布

JDBC连接SQL Server访问出错

报错一:com.microsoft.sqlserver.jdbc.SQLServerException: 用户 ‘sa’ 登录失败

1、问题:

通过用户名 sa 连接 SQL Server 数据库报错。

2、报错信息:

com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。 ClientConnectionId:c21ee6ce-53fa-4e75-af98-04460287ad7f
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
	at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:279)
	at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:99)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4346)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3160)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3123)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2445)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1981)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at cn.hestyle.test.Test01.<clinit>(Test01.java:21)
Exception in thread "main" java.lang.NullPointerException
	at cn.hestyle.test.Test01.main(Test01.java:30)

3、解决办法

:SQLServerSQLServer

重启SQL Server服务方法

SQLServer

③、检查是否开启SQL Server Browser服务

报错二、com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“connect timed out。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。

1、问题:

TCP/IP 1433端口连接失败

2、报错信息

com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“connect timed out。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还要确保防火墙没有阻止到此端口的 TCP 连接。”。
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191)
	at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242)
	at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2369)
	at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:551)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1963)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at cn.hestyle.test.Test01.<clinit>(Test01.java:21)
Exception in thread "main" java.lang.NullPointerException
	at cn.hestyle.test.Test01.main(Test01.java:30)

3、解决方法

①、检查SQL Server 配置的是否为1433端口、以及TCP/IP协议是否启动

在启动菜单中知道SQL Server配置管理器
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
SQLServer

检查了一下午,翻了百度几次。。。很多博客说是防火墙的问题,经过测试,连接本地的SQL Server与端口的防火墙没有关系,连接远程的SQL Server才需要设置防火墙。

如果你看到这都还不 com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭。 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:130) at com.microsoft.sqlserver... 开发环境:SpringBoot + Sql Server 2008R2。pom 文件配置好之后,启动项目提示【连接已关闭】原因:驱动包版本与SqlServer版本不匹配。 2.SQL Server 身份验证模式:检查 SQL Server 的身份验证模式设置。你可以尝试使用 SQL Server Management Studio (SSMS) 或其他具有足够权限的账户登录 SQL Server,然后修改 SA 账户的默认数据库为一个可用的数据库。6.SQL Server 错误日志:查看 SQL Server 的错误日志,获取更详细的错误信息。你可以尝试使用其他有足够权限的账户登录 SQL Server,并检查 SA 账户的状态,以确定是否被禁用。这是默认的身份验证模式。 转载▼  使用 JDBC 连接数据库时候,前些天还好好的,突然就不能用了,报了下边的错误at com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。 错误原因是登录失败第一步:考虑是数据库没有配置为双身份认证模式经过核实,配置是正确的,没有错误第二步:考虑是 properties 文件中 sa 用户密码写错了经过核实,没有错,而... 先来一份报错内容: com.microsoft.sqlserver.jdbc.SQLServerException: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhostTCP/IP 连接失败。 在使用SQL Server数据库建立与jsp的联系时出现了,打开浏览器访问所写的jsp网页时报以下错误信息: com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhostTCP/IP 连接失败。 提示:以下是本篇文章正文 自己遇到这个问题试了好多方法,却没有想到... 在下图里面可以看见,SQl server网络配置中有两个协议,java开发,使用第二个MSSQLSERVER协议 我的问题是服务中,服务中,启动的是SQLEXPRESS服务 解决方法:在下图中点击“服务”项,将“SQL serverSQLEXPERSS)”禁用,同时启动“SQL server(MSSQLSERVER)” JDBC连接SQL Server访问出错 报错一:com.microsoft.sqlserver.jdbc.SQLServerException: 用户sa登录失败 报错二:com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1433 连接到主机 localhostTCP/IP 连接失败。错误:“connect timed out。请验证连接属性。确保 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接,还 Pro SQL Server Wait Statistics is a practical guide for analyzing and troubleshooting SQL Server performance using wait statistics. Whether you are new to wait statistics, or already familiar with them, this book will help you gain a deeper understanding of how wait statistics are generated and what they can mean for your SQL Server’s performance. Besides the most common wait types, Pro SQL Server Wait Statistics goes further into the more complex and performance threatening wait types. The different wait types are categorized by their area of impact, and include CPU, IO, Lock, and many more different wait type categories. Filled with clear examples, Pro SQL Server Wait Statistics helps you gain practical knowledge of why and how specific wait times increase or decrease, and how they impact your SQL Server’s performance. What you’ll learn How wait Statistics are generated by SQL Server Script examples for analyzing and tuning wait statistics How to lower, or even eliminate, wait times that hurt performance How to query wait statistics information from Dynamic Management Views How to build reliable and solid wait statistics baselines from which to detect performance issues Who this book is for Pro SQL Server Wait Statistics is the perfect guide for SQL Server DBAs wanting to troubleshoot and optimize SQL Server database installations. The book is also of interest to database developers who are serious about developing highly-performant applications and reporting systems. Table of Contents Part I: Foundations of Wait Statistics Analysis 23 Chapter 1: Wait Statistics Internals Chapter 2: Querying SQL Server Wait Statistics Chapter 3: Building a Solid Baseline Part II: Wait Types Chapter 4: CPU-Related Wait Types Chapter 5: IO-Related Wait Types Chapter 6: Backup-Related Wait Types Chapter 7: Lock-Related Wait Types Chapter 8: Latch-Related Wait Types Chapter 9: High-Availability and Disaster-Recovery Wait Types Chapter 10: Preemptive Wait Types Chapter 11: Background and Miscellaneous Wait Types Chapter 12: In-Memory OLTP–Related Wait Types Appendix I: Example SQL Server Machine Configurations Appendix II: Spinlocks Appendix III: Latch Classes com.microsoft.sqlserver.jdbc.SQLServerException: 对象名  ‘xxx' 无效。 环境:sqlserver 2008/2005都可以 如果查询时出现以上错误提示, 1.首先检查数据库表名称是否有拼写错误,若有,改正后测试下。 2.其次检查数据库连接是否成功,可暂时将SQL以及相关语句注释,测试。 3.若以上两种都无法解决,则:出现的错误是 public static void main(String[] args) { String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String dbURL="j