1

I'm trying to connect to my local SQL Server Database. The database name is MDB and those are the credentials I use. Tried with user="User" as well and it didn't work.
I have the following jar into my library: jtds-1.3.1.jar
The version of SQL server I use is 2012.

String url = "jdbc:jtds:sqlserver://localhost:1344/MDB;instance=sqlserver;useNTLMv2=true;";
String user = "User-PC\\User";
String pass = "";

I also tried with localhost:1099 and no success.

try
{
    Class.forName("net.sourceforge.jtds.jdbc.Driver");
}
catch (ClassNotFoundException e){
    e.printStackTrace();
    System.out.println("1st error");
}
try
{
    Connection con = DriverManager.getConnection( dbUrl, dbUser, dbPwd );
    System.out.println("Worked");
} catch (SQLException e){
    e.printStackTrace();
    System.out.println("Driver error");
}

I have the JTDS jar into my external libraries. The error I get is the following:

java.sql.SQLException: Network error IOException: Connection refused: connect at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:436) at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at Main.main(Main.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288) at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251) at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331) ... 9 more

Info from SQL: Login name:User-PC\User Server name: USER-PC

Simply Me
  • 1,579
  • 11
  • 23
  • 1
    Try port `1433`, I believe this is the default port. – hmjd Apr 15 '16 at 11:27
  • check if your server is working or not – SpringLearner Apr 15 '16 at 11:27
  • @SpringLearner, yes, I checked the config manager and tried even from db directly and it's up and running. – Simply Me Apr 15 '16 at 11:29
  • @hmjd, same error. Would it be possible to fix it with the microsoft version? – Simply Me Apr 15 '16 at 11:34
  • For both sqlexpress and mssqlserver... Maybe is a problem that I have both 2008 and 2010 versions? – Simply Me Apr 15 '16 at 11:38
  • @wero good ideea! Let me check. – Simply Me Apr 15 '16 at 11:43
  • 2
    Possible duplicate of [What is the jTDS JDBC Connect URL to MS SQL Server 2005 Express](http://stackoverflow.com/questions/1045958/what-is-the-jtds-jdbc-connect-url-to-ms-sql-server-2005-express) – Filburt Apr 15 '16 at 11:44
  • @Filburt, I already tried that, saw the post before asking the question. It didn't solve my problem. Also, turned firewall off and it didn't fix anything. – Simply Me Apr 15 '16 at 11:49
  • @SimplyMe [Help me create a jTDS connection string](http://stackoverflow.com/q/1862283/205233) also has more points to check (if you didn't already find it). – Filburt Apr 15 '16 at 12:06
  • Checked the firewall (disabled). Checked the antivirus, checked the port, the jar, redownloaded it, restart sql server, recheck if it's active... – Simply Me Apr 15 '16 at 12:10
  • If you connect to an instance, you need to drop the port and make sure the SQL Server Browser service is running. – Mark Rotteveel Apr 15 '16 at 14:45

1 Answers1

3

You need to make sure TCP/IP ports are enabled in SQL server configuration and the SQL Server Browser service is also running.

IanB
  • 449
  • 4
  • 11