【发布时间】:2013-09-23 11:57:10
【问题描述】:
我试图连接到安装在远程系统上的 ms sql server 2008。但它显示错误。以下是我尝试过的方式
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class mssql {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection connection=DriverManager.getConnection("jdbc:sqlserver://192.168.1.220:1433;databaseName=sales;integratedSecurity=true;");
if(!(connection==null))
{
System.out.println("connected");
}
//
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是我遇到的错误
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.1.220, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at mssql.main(mssql.java:14)
此问题的任何解决方案
【问题讨论】:
-
可以通过SQL Server Management Studio或者“telnet 192.168.1.220 1433”访问远程服务器吗?
-
@Rainer.R 说无法打开连接
-
@Rainer.R 我的 Windows 防火墙阻止了它,现在我可以远程登录了。但我无法连接到 sql server
-
"连接超时。验证连接属性。确保 SQL Server 实例正在主机上运行并且在端口接受 TCP/IP 连接。确保到端口的 TCP 连接未被防火墙阻止。"
标签: java sql sql-server jdbc