使用默认连接字符串(管理控制台说要使用的连接字符串)使用JDBC连接到Azure SQL的证书异常 [英] Certificate Exception connecting to Azure SQL with JDBC with default connection string (the one the management console says to use)

查看:85
本文介绍了使用默认连接字符串(管理控制台说要使用的连接字符串)使用JDBC连接到Azure SQL的证书异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从jdbc连接到Azure SQL Server.

I'm wanting to connect to an Azure SQL Server from jdbc.

我从azure管理控制台复制连接字符串.就像这样:

I copy the connection string from the azure management console. It is something like:

jdbc:sqlserver://XXXX.database.windows.net:1433; database = YYYY; user = ZZZZZ @ XXXX; password = PPPPPPPPPPP; encrypt = true; hostNameInCertificate = *.database.windows.net

jdbc:sqlserver://XXXX.database.windows.net:1433;database=YYYY;user=ZZZZZ@XXXX;password=PPPPPPPPPPP;encrypt=true;hostNameInCertificate=*.database.windows.net

当我尝试使用此值进行连接时,出现以下错误:

When I try and connect with this value I get the following error:

com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法 通过使用安全套接字建立到SQL Server的安全连接 层(SSL)加密.错误: "java.security.cert.CertificateException:无法验证 安全套接字层(SSL)期间证书中的服务器名称 初始化.服务器名称为* .database.windows.net,名称为 证书是data.am2-1.database.windows.net.

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization. The server name is *.database.windows.net, the name in certificate is data.am2-1.database.windows.net.

然后,如果我将* .database.windows.net更改为data.am2-1.database.windows.net,那么它会正常工作.

Then if I change the *.database.windows.net to data.am2-1.database.windows.net as it says in the exception it works fine.

那么设置这个名字有问题吗?我觉得如果默认情况下是通配符,那么它可能会改变吗?我什么时候会再也无法连接了. 其他人遇到过这个问题吗?我正在使用可以找到的用于SQL Server的最新jdbc驱动程序.

So is it a problem to set this name? I feel like if it is a wild card as default then it is probably going to change? and when it does I assume I won't be able to connect anymore. Has anyone else had this issue? I am using the most up to date jdbc drivers for SQL Server that I could find.

推荐答案

将sql server jdbc版本升级到版本4.0可以解决此问题.

Turns out an upgrade of the sql server jdbc version to version 4.0 cleaned up the issue.

这篇关于使用默认连接字符串(管理控制台说要使用的连接字符串)使用JDBC连接到Azure SQL的证书异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆