Unable to connect to SQL Server using Node.js and Tedious

When I try to use Node.js and Tedioius to connect to a local instance of SQL Server, I get this error:

{ [ConnectionError: Failed to connect to XXXXX:1433 - connect ECONNREFUSED] name: 'ConnectionError', message: 'Failed to connect to XXXXX:1433 - connect ECONNREFUSED', code: 'ESOCKET' } 

Here is my connection object:

 var config = { userName: 'username', password: 'password', server: 'XXXXX', options: { database: 'databasename', instancename: 'SQLEXPRESS' } }; 

I checked and TCP / IP is enabled and is being broadcast on port 1443 according to Configuration Manager. The SQL Server Browser service also works, which, as I read, can cause this type of problem, if not. I disabled my antivirus and firewall, and that didn't help either.

Any insight?

+7
javascript sql-server tcp tedious
source share
4 answers

So, I suppose that even if Tedious allows you to include the instance name in the "parameters", it either does not use it or cannot use it, since it should be used. After some research on what should happen when you give SQL Server an instance name, it redirects you from port 1433 to the dynamic port that it uses for that instance. I did not know that it uses a dynamic port, but if your instance is named, the port will always be dynamic. I do not know where I saw his broadcast in 1433, it was my mistake.

To check the dynamic port, see here:

enter image description here

From this information, I changed the code to this:

 var config = { userName: 'username', password: 'password', server: 'XXXXX', options: { port: 49175, database: 'databasename', instancename: 'SQLEXPRESS' } }; 

Now everything is fine, I hope this helps someone.

+13
source share

If you still got this error,

" ..." Failed to connect to the Server: 1433 - connect ECONNREFUSED Server IP: 1433 ', code: "ESOCKET"} "

and you checked all of the following:

  • Enable TCP / IP
  • Open port 1433
  • The configuration is configured correctly (database, server, username and password)
  • No configured dynamic ports.

Check the version of SQL server. In my case, I found that I could connect to SQL 2012, but not SQL Server 2016 with the same code. Apparently, SQL Server 2016 is not yet supported by a tedious driver.

+1
source share

If someone else is not familiar with SQL Server like me and solves this problem by enabling TCP / IP in SQL Server Configuration Manager, follow these steps:

> SQL Server Network Configuration

> Protocols for YOURSQLSERVERINSTANCE

TCP / IP

> Enable

a warning message appears that looks like this:

All changes made will be saved; however, they will not take effect until the service is stopped and restarted.

I figured this out to disconnect from the database service in SQL Server Management Studio and reconnect, but this should happen in SQL Server Config Manager on the SQL Server Services tab. Find the instance of SQL Server, stop and restart it, and I hope you become gold! It worked for me like a charm. Oddly enough, turning on the Named Pipes protocol seemed to work without a reboot (I could see the difference in the error message), so I thought it stopped and restarted as needed.

Also, be sure to enable SQL Server Browser Services . This and enabling TCP / IP and restarting the service were keys to me.

+1
source share

If you still have problems after enabling TCP / IP, I suggest you check the SQL Server Browser service. In my case, I spent a lot of time until I realized that it was not working.

This configuration works fine for me:

  var config = { user: 'user', password: 'userPwd', server: 'localhost', database: 'myDatabase', options: { truestedConnection: true, instanceName: 'SQLEXPRESS' } 
0
source share

All Articles