Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not connect to the database Network error IOException: Connection refused: connect

I am running a SQL Server Express 10.50.4000.0 on my machine. I have enabled on the TCP/IP and made sure the port is set to 1433. I have added an exception in my firewall for 1433. The server service is running. I have tried localhost and the computer name and both give the same error. When i try localhost\SQLEXPRESS or [USER-PC]\SQLEXPRESS I received an error saying it could not find the database.

String driverName = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driverName);

String serverName = "localhost";
String instanceName = "ALLEN-PC\\SQLEXPRESS";
String serverPort = "1433";
String database  = serverName +":" + serverPort+"/"+instanceName;
String url = "jdbc:jtds:sqlserver://" + database;
String username = "sa";
String password = "password";

connection = DriverManager.getConnection(url, username, password);

I receive the error:

Could not connect to the database Network error IOException: Connection refused: connect

with no additional context to investigate.

like image 645
Allen Avatar asked Aug 02 '13 15:08

Allen


1 Answers

  1. Make Sure that your SQL Server Browser service is active.
  2. Goto AllProgram->SQL Server ->configuraton tools->SQL Server Configuration Manager->SQL Server Network Configuration-> Select your server instance and right click on TCP/IP then goto IPAddresses. Change/Place port number for all IP's as 1433. Also make sure that the IP Address is Active and Enabled. Save it and restart the server.
like image 117
vsriram92 Avatar answered Sep 23 '22 21:09

vsriram92