0

I am recently trying to configure MS SQLServer with JDBC driver , I have installed SQL SERVER EXPRESS edition 2016 and JDBC DRIVER 4(sqljdbc 4.0).After modifying and running sample code from net for my own test purpose I have got this error

com.microsoft.sqlserver.jdbc.SQLServerException: The server sqlexpress is not configured to listen with TCP/IP.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3603)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at JdbcTest.main(JdbcTest.java:24) 

I have taken these step for the solution
1.I have disabled firewall
2.Enable TCP/IP for SQLSERVER(SQLEXPRESS) from configuration manager
3.I have given port number 1434
4.Enabled SQL Browser Services

But the code did not compiled. here is my code :

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcTest {





    public static void main (String[]args)

    {   

        Connection con=null;
        try{
            String dbURL = "jdbc:sqlserver://localhost\\SQLEXPRESS;user=codemen;password=";

            //String user="codemen";
            //String password="cd";
            //DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

            con=DriverManager.getConnection(dbURL);
            if(con!=null)
            {
                DatabaseMetaData dm=(DatabaseMetaData)con.getMetaData();
                System.out.println("Driver name: "+" " +dm.getDriverName());
                System.out.println("Driver version :" +" "+ dm.getDriverVersion());
                System.out.println("Product name: " + dm.getDatabaseProductName());
                System.out.println("Product version: " + dm.getDatabaseProductVersion());

            }

        }
        catch(SQLException ex)
        {
            ex.printStackTrace();

        }
        finally
        {
            try{
                if (con !=null && !con.isClosed())
                {
                   con.close(); 
                }
            }
            catch(SQLException sq)
            {
                sq.printStackTrace();
            }
        }
    }

}

It will be great help if i got a guideline for overcoming this issues. Thanks in advance

Kalyan
  • 1,880
  • 11
  • 35
  • 62
  • 3
    possible dublicate with [this](http://stackoverflow.com/questions/11820799/com-microsoft-sqlserver-jdbc-sqlserverexception-the-tcp-ip-connection-to-the-ho) – Niku Hysa Jul 18 '16 at 12:55
  • "I have given port number 1434" Typo? If not, include the port in the URL, as 1433 is the default. – Liesel Jul 18 '16 at 13:03
  • Did you restart the SQL Server instance after enabling TCP/IP? – Gord Thompson Jul 18 '16 at 15:05
  • Thanks for reply .i restarted the sql server instance after enabling and i hope it works i am not getting this error but new error occur that is login failed for user. i tried sql server properties log on tab my built in account local system and this account field is mssql express . does sql-express has default user and password .I could not configure it – Kalyan Jul 19 '16 at 04:27
  • *"does sql-express has default user and password"* - No. You will need to provide valid credentials for that particular SQL Server instance. If you need help with that then you should [ask a new question](http://stackoverflow.com/questions/ask). – Gord Thompson Jul 21 '16 at 16:29

0 Answers0