连接到SQL Server时出现SQL异常 [英] SQL Exception while connecting to SQL server

查看:243
本文介绍了连接到SQL Server时出现SQL异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个重复的问题。我发现了非常类似的问题和解决方案,但我仍然很震惊。

I know that this is a repeated question. I have found very similar questions and solutions to them but still i'm struck with it.

我正在使用eclipse将我的java应用程序与microsoft sql server 2008数据库连接起来。以下是我的代码

I'm using eclipse to connect my java application with microsoft sql server 2008 database. Following is my code

    import java.sql.*;
public class ConnectionTest2 {
  public static void main(String [] args) {
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=Sample;integratedSecurity=true";
        Connection con = DriverManager.getConnection(connectionUrl,"","");
        System.out.println("Connected");
        } catch (SQLException e) {
            System.out.println("SQL Exception: "+ e.toString());
        } 
catch (ClassNotFoundException cE) {
            System.out.println("Class Not Found Exception: "+ cE.toString());
        }
  }
}

我启用了tcp / ip和VIA进入sql server配置管理器并在IPALL下将端口号设置为1433.

I've enabled the tcp/ip and VIA by going in to sql server configuration manager and set the port number to 1433 under IPALL.

我尝试了很多方法,但我无法找到以下错误的解决方案

I've tried in many ways but i'm unable to find a solution to the following error


SQL异常:com.microsoft.sqlserver.jdbc.SQLServerException:
TCP / IP连接到主机localhost,端口1433失败。错误:
连接被拒绝:连接。验证连接属性。确保
确保主机上运行SQL Server实例,并且
接受端口上的TCP / IP连接。确保防火墙不会阻止与端口的TCP
连接。。

SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 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.".

我还禁用了Windows防火墙但无法连接。

I've also disabled the windows firewall but failed to connect.

请帮帮我。

推荐答案

它是这样说的:连接被拒绝了。你试过'telnet 1433'吗?

It is what it says: connection is refused. Have you tried 'telnet 1433'?

这篇关于连接到SQL Server时出现SQL异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆