Results 1 to 2 of 2
  1. #1
    tanvirtonu is offline Member
    Join Date
    Mar 2008
    Rep Power

    Default Sql server connection problem

    I m using SQL server 2005 express. My default logon mode setting is set to-SQL server authentication and I can logon to using SQL server management studio express always. I enabled TCP/IP from SQL server configuration manager. The sqljdbc.jar (JDBC driver) is set correctly in classpath and 1433 port is allowed in windows firewall. YET, I canít connect to sql server using the following code-
    Java Code:
    import java.sql.*;
    public class testconn {
    Statement stmt;
    Connection con = null;
           		String driver = "jdbc:sqlserver://";
    		String server = "localhost:1433;";
    		String db = "database=IDLC-Customer;";
    		String user = "userName=Tanvir;";
    		String pwd = "password=abcd;";
    		String connectName = driver + server + db + user + pwd;     	
    {	 try {
          con= DriverManager.getConnection(connectName);
            System.out.println("Successfully connected to " +
              "SQL server using TCP/IP...");
         } catch(Exception e) {
          System.err.println("Exception: " + e);    } 
     finally {     try {
            if(con != null)
            } catch(SQLException e) {}    			}         	
      public static void main(String args[]) {
        testconn tc=new testconn();
    My host name is- Tanvir. So, in management studio express the server name is shown- TANVIR\SQLEXPRESS
    When I run the code it says-The TCP/IP connection to the host has failed. Refused: Connect
    One more thing, though 1433 port is allowed in windows firewall, I canít connect to that port using telnet (e.g. telnet <server_host> 1433).I even disabled firewall and tried but in vain. PLEASE help me any brother.

  2. #2
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    London, UK
    Rep Power


    The code all looks good to me. Are you able to telnet to any other open port on your machine?
    Did this post help you? Please me! :cool:

Similar Threads

  1. Replies: 2
    Last Post: 07-15-2008, 07:11 PM
  2. connection problem
    By subash in forum JDBC
    Replies: 5
    Last Post: 04-22-2008, 10:17 AM
  3. Java Serevr Connection Problem
    By virendra_agarwal in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 12-19-2007, 01:43 PM
  4. SQL Server 2005 Jdbc connection
    By mgt83 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-27-2007, 05:52 AM
  5. JDBC driver connection problem
    By creativehacker in forum JDBC
    Replies: 3
    Last Post: 07-10-2007, 10:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts