Connection to local MS SQL Server

I have a local MS SQL Server and am trying to connect to it using JTDS in java. Here is the connection string:

Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock","sa","password");

And server properties:
name: USER-PC \ SQLEXPRESS
root directory: c: \ Program Files \ Microsoft SQL Server \ MSSQL11.SQLEXPRESS \ MSSQL

I get an error Exception in thread "main" java.sql.SQLException: Network error IOException: Connection refused: connect.

How can i fix this?

+5
source share
3 answers

Check the following:

  • You have enabled security in mixed mode, i.e. you can connect with username / password (and not using Windows authentication).
  • TCP / IP is enabled. Open SQL Server Configuration Manager, then in the SQL Server network configuration, select Protocols and Enable TCP / IP.
  • getConnection, :

    DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/stock;instance=SQLEXPRESS;user=sa;password=password")
    
  • ( ), SQL Server ( ). , , , , .

+10

1433 - , . SQLEXPRESS, . :

sqlserver://localhost\SQLEXPRESS
0

SQL Server Browser Service is disabled by default. If you are developing a .Net application, you do not need to run SQLBrowser, but if you use JTDS in java, you will need to run it.

0
source

All Articles