【发布时间】:2018-10-01 11:02:03
【问题描述】:
这是我编写的代码的一部分:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String host1 = "<URL/Connection path string>";
String uname1= "<User name>";
String pwd1 = "<Password>";
Connection con1 =DriverManager.getConnection(host1,uname1,pwd1);
Statement stmt1 = con1.createStatement();
ResultSet rs = stmt1.executeQuery("<Query>");
我使用过以下 jar 文件:jtds-1.3.0、sqljdbc-4.1.5605、sqljdbc4-4.0
当我运行代码时,出现以下错误:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host <host-name>, named instance <instance-name> failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3589)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
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(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at first_doc.main(first_doc.java:28)
据我所知,没有防火墙阻止流量。
另外,我需要添加端口号作为连接 URL 的一部分吗?
编辑:我使用 SQL Server 2008 版
我在配置管理器中找不到 SQLEXPRESS 的协议
【问题讨论】:
-
您的实际代码是原样吗?我的意思是
String host1 = "<URL/Connection path string>";之类的? -
你的sql server是在后台运行的吗?
-
@Cid 不,出于隐私原因,我已对其进行了修改。
-
@Arty,是的
-
@TRV 好的,我只是想确定一下 :)
标签: java sql sql-server