2011-09-02 55 views
0

我在eclipse项目的Build路径中使用了sqljdbc4.jar。 我试图连接到SQL Server 2008在Java程序中无法在Java程序中连接SQL Server 2008的本地实例

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
String connectionUrl = "jdbc:sqlserver://localhost:1433;" + 
      "databaseName=sis;user=sample;password=sample;"; 
     connection = DriverManager.getConnection(connectionUrl); 

但我收到以下错误。 与主机的TCP/IP连接失败。 java.net.ConnectException:连接被拒绝:连接

我尝试以下

  • 防火墙关闭

  • 启用TCP/IP在SQL Server配置管理器 - >客户端协议

  • SQL Server浏览器服务也在运行 请让我知道我应该尝试其他什么。

由于

+2

您是否尝试使用SQL Server Management Studio连接到数据库服务器实例? –

+0

是的,我尝试过。我能够做到。我们需要做一些关于SQL Server的设置。 –

回答

1

防火墙关闭该方式,这种方式???开/启用端口本地主机:1433个

运行CMD,并从

的Windows authe ......到SQL Server和Windows认证(混合模式)粘贴

netsh firewall set portopening protocol = TCP port = 1433 
name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT 

2 /更改SQL Server身份验证

3)您的版本是SQL Server 2008或SQL Server 2008 Express,如果是Express,那么搜索下载的软件包(包含excelenct inc inc examples)如何连接Express在Localhost上,有区别localhost \ sqlexpress

hereherehere

4)不知道如何连接,有TCP/IP和命名管道太

编辑:

5)Management Studio中必须添加新用户(SQL的autenthification)和分配给决策数据库(无论或模型太)是吗?是不是

+0

嗨,我有SQL Server 2008企业版。 1)我在防火墙中添加了端口1433的例外 2)身份验证是混合模式 3)用户已添加到服务器上。我可以看到它在安全 4)另外,尝试CMD评论你给。 即使这样做,问题仍未解决。 –

相关问题