sql-server - 到主机的 TCP/IP 连接,端口 1433 失败

标签 sql-server jdbc tcp

我是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/

相关文章:

sql-server - 如何在Sql Server 2008中加密数字列?

python - 如何在 Windows 中安全地存储数据库凭据?

sql-server - 检测表中非 ASCII 的 UNICODE 字符

java - 以编程方式在 Hibernate 中设置数据库 url/用户/密码

networking - Nagle 算法和延迟确认

sql-server - 合计投票结果

java - 为 Jboss EAP 6.3 安装 JDBC

java - 如何在不使用不同的准备语句的情况下处理 NULL 和常规值?

perl poe tcp 服务器处理多个客户端

c - 通过c中的套接字从结构传递字符