-1

我无法使用 java 连接 SQL Server 2008 R2。相同的代码适用于 SQL Server 2005。

我试图找出 sqlserver 服务的端口和 ip,它给了我

ip - 0.0.0.0 and port 1434 

我尝试使用与 SQL Server 2005 相同的连接字符串,但它在 SQL Server 2008 中对我不起作用。这是我的连接字符串:

conn=DriverManager.getConnection(jdbc:sqlserver://127.0.0.1:1434:DatabaseNameconnect?autoReconnect=true,user, password);

这是错误:

jdbc:sqlserver://127.0.0.1:1434;DatabaseName=connect;user=falcon;Password=admin
Could not connect to database
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host  has failed. java.net.ConnectException: Connection refused: connect
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.dnb.discovery.connection.ConnectionBean.makeMsSqlConnection(ConnectionBean.java:62)
    at com.dnb.discovery.factory.MssqlDAOFactory.<init>(MssqlDAOFactory.java:18)
    at com.dnb.discovery.dao.mssqldao.MssqlCompanyDAO.<init>(MssqlCompanyDAO.java:8)
    at com.dnb.discovery.relevance.Relevance.modifyRelevanceIndex(Relevance.java:67)
    at com.dnb.discovery.relevance.Relevance.calulateRelevanceScore(Relevance.java:36)
    at com.dnb.discovery.dao.SolrDAO.readDataFromSolr(SolrDAO.java:222)
    at com.dnb.discovery.searchservice.SearchService.buyerTextSearchAnonymous(SearchService.java:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
    at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

有什么帮助吗?

4

2 回答 2

1

您的问题有很多可能性:

  • 防火墙
  • 没有 TCP/IP 连接器
  • 一些服务没有运行

尝试使用 SQL-management Studio 连接到您的数据库。如果这可行,请尝试通过 TCP/IP 使用 SQL-Authentification 进行连接。

更新

查看http://msdn.microsoft.com/en-en/library/ms143693(v=sql.90).aspx上的文档

于 2012-05-24T15:07:39.757 回答
0

一个明显的问题是 SQL Server 侦听端口 1433,而不是 1434。我已经在其他地方回答过这个问题,但我不能确定它是否与您的问题完全匹配,因为您没有告诉我们您的错误消息是什么得到。

于 2012-05-24T14:40:35.527 回答