1
我收到以下错误:com.microsoft.sqlserver.jdbc.SQLServerException:驱动程序无法建立与SQL的安全连接服务器通过使用安全套接字层(SSL)加密。错误:“通过peer重置连接:套接字写入错误。”由于SSL问题,无法使用JDBC(基于连接字符串和样本提供)连接到Azure
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;
public class SQLDatabaseConnection {
// Connect to your database.
// Replace server name, username, and password with your credentials
public static void main(String[] args) {
String connectionString =
"jdbc:sqlserver://XXXXX.database.windows.net:1433;"
+ "database=VDB;"
+ "[email protected];"
+ "password=XXXX;"
+ "encrypt=true;"
+ "trustServerCertificate=false;"
+ "hostNameInCertificate=*.database.windows.net;"
+ "loginTimeout=30;";
// Declare the JDBC objects.
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(connectionString);
// Create and execute a SELECT SQL statement.
String selectSql = "SELECT TOP 2 * from Application";
statement = connection.createStatement();
resultSet = statement.executeQuery(selectSql);
// Print results from select statement
while (resultSet.next()) {
System.out.println(resultSet.getString(2) + " "
+ resultSet.getString(3));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close the connections after the data has been handled.
if (resultSet != null) try {
resultSet.close();
} catch (Exception e) {
}
if (statement != null) try {
statement.close();
} catch (Exception e) {
}
if (connection != null) try {
connection.close();
} catch (Exception e) {
}
}
}
}
我只是试图做的代码“样本”连接段上在Azure网站(指向MS输入)作为参考的,仅修改,以配合我的数据库和测试表,但没有成功。
在审查所有有知道的,我有: -
- 确保我使用权sqljdbc(我已经尝试了所有4)
- 有sqlauth.dll在CLASSPATH
- 已将样品完全设置为如图所示;并包含Azure提供的字符串。
我试过各种加密和信任的组合,但没有成功。由于我是Java和Azure的新手,我不愿意并且不确定如何摆脱JVM安全设置。我已经证明我的机器可以与Azure数据库(通过VB ODBC连接)通信;我已经用防火墙测试过了。
有什么想法?
如果在SQL Azure中选择1 + 1结果为4,则可能需要提交错误报告;) –