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

    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;     	
    	testconn()
    {	 try {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          con= DriverManager.getConnection(connectName);
          stmt=con.createStatement();
           if(!con.isClosed())
            System.out.println("Successfully connected to " +
              "SQL server using TCP/IP...");
         } catch(Exception e) {
          System.err.println("Exception: " + e);    } 
         
     finally {     try {
            if(con != null)
              con.close();
            } 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.
    Java.net.connectException:Connection 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
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    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, 06:11 PM
  2. connection problem
    By subash in forum JDBC
    Replies: 5
    Last Post: 04-22-2008, 09:17 AM
  3. Java Serevr Connection Problem
    By virendra_agarwal in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 12-19-2007, 12:43 PM
  4. SQL Server 2005 Jdbc connection
    By mgt83 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-27-2007, 04:52 AM
  5. JDBC driver connection problem
    By creativehacker in forum JDBC
    Replies: 3
    Last Post: 07-10-2007, 09: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
  •