我是JDBC连接的新手,很迷茫。我启用了 TCP/IP 和命名管道,并在 TCP/IP -> IP 地址中将 TCP 端口设置为 1433 并重新启动了服务器。我还通过具有高级安全性的 Windows 防火墙打开了对 SQL Server 的访问权限。问题是我仍然收到此错误:
SQLException: The TCP/IP connection to the host MSSQL$SQLFULL, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port."
我在 cmd 上运行以下命令:telnet SQLFULL 1433
并且我收到此消息:
无法在端口 1433 上打开与主机的连接:连接失败
我的代码:
String url = "jdbc:sqlserver://MSSQL$SQLFULL:1433;databaseName=BA_ELTRUN;";
Connection dbcon = null;
String errorMessages = "";
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.out.print("ClassNotFoundException: ");
System.out.println(e.getMessage());
}
try
{
dbcon = DriverManager.getConnection(url,"username","password");
}
catch(SQLException e)
{
System.out.print("SQLException: ");
System.out.println(e.getMessage());
errorMessages = "Could not close connection with the Database Server: <br>"
+ e.getMessage();
throw new SQLException(errorMessages);
}
有人能帮忙吗?
最佳答案
复制计算机名称:cmd.exe -> hostname
或
右键单击“开始”,然后单击“系统”并复制计算机名
网址应该是:
String url = "jdbc:sqlserver://<Computer Name>\\SQLFULL:1433;databaseName=BA_ELTRUN;";
Connection conn = DriverManager.getConnection(url,"<user>","<password>"):
关于sql-server - 到主机的 TCP/IP 连接,端口 1433 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34692849/