0

I am trying to connect to a SQL database on a machine on my network. From what I can tell the TCP/IP settings and Firewall settings are all correct to be able to connect, but I am having no luck with my connection string.

Code:

static String dbUser = "user";
static String dbPass = "pass";
static String dbURL = "jdbc:sqlserver://SERVER1/BKUPEXEC;Instance=SQL2005;databaseName=images;";
static String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

try {
        Class.forName(driverName).newInstance();
        con = DriverManager.getConnection(dbURL, dbUser, dbPass);
        System.out.println("Connected with host:port/database.");
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException |    SQLException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

Error:

SEVERE: null
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host TMTSERVER1, port 1433 has failed. Error: "connect timed out. 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.".
Aaron Lemon
  • 25
  • 1
  • 5

2 Answers2

0

try

"jdbc:sqlserver://SERVER1/BKUPEXEC;instanceName=SQL2005;databaseName=images;"
                                   ^^^^^^^^^^^^
jlordo
  • 37,490
  • 6
  • 58
  • 83
  • New error: com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host TMTSERVER1/BKUPEXEC, named instance SQL2005 failed. Error: "java.net.UnknownHostException: TMTSERVER1/BKUPEXEC". – Aaron Lemon Mar 15 '13 at 15:53
  • look at [What causes the error - java.net.UnknownHostException](http://stackoverflow.com/questions/6484275/what-causes-the-error-java-net-unknownhostexception) – jlordo Mar 15 '13 at 15:58
0

I ended up changing the connection string to use the server's IP address instead of it's domain name. Also turns out that the SQL server was not using the default port number.

This is the new working connection string:

static String dbURL = "jdbc:sqlserver://192.168.1.240:1053;databaseName=SI_images;";
Aaron Lemon
  • 25
  • 1
  • 5