简体   繁体   English

连接到Microsoft SQL Server时出错

[英]Error while connecting to Microsoft SQL Server

I am trying to connect to MS SQL Server 2005 from java, I am getting the following error, can anyone help me ? 我正在尝试从Java连接到MS SQL Server 2005,出现以下错误,有人可以帮助我吗?

private static final String DRIVER_CLASS = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; 
Class.forName(DRIVER_CLASS); 
DriverManager.getConnection("jdbc:sqlserver://localhost:1433","sa","root");

I added the following 5 jar files : 我添加了以下5个jar文件:

  • msbase msbase
  • mssqlserver mssqlserver
  • msutil msutil
  • sqljdbc sqljdbc
  • sqljdbc4 sqljdbc4

The exception is : 例外是:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
 at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
 at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
 at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
 at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
 at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
 at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
 at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
 at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Source)

Is you firewall on? 您是否在防火墙上? If so, maybe you will need to make an exception for port 1433 如果是这样,也许您需要为端口1433设置例外

Please check what protocols are enabled on the server. 请检查服务器上启用了哪些协议。 Go to Start/Programs/Microsoft |SQL Server 2005/Configuration Tools/SQL Server Configuration Manager. 转到“开始/程序/ Microsoft SQL Server 2005 /配置工具/ SQL Server配置管理器”。 Check if tcp is enabled under SQL Server 2005 Network Configuration/Protocols for MSSQLSERVER. 检查是否在SQL Server 2005网络配置/协议下为MSSQLSERVER启用了tcp。

Please check if you don't have named instance - SQL Server Express edition by default creates a named instance for example. 请检查您是否没有命名实例-默认情况下,SQL Server Express版本会创建一个命名实例。

And the third - check if SQL Server has mixed mode authentication - if not it will not allow you to connect using SQL login and password. 第三个-检查SQL Server是否具有混合模式身份验证-否则,将不允许您使用SQL登录名和密码进行连接。 BTW it is a bad idea to use sa account to develop applications. 顺便说一句,使用一个帐户来开发应用程序是一个坏主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM