Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to connect to local sqlexpress - but can connect in management studio #655

Closed
spacem opened this issue Nov 30, 2017 · 4 comments
Closed

Comments

@spacem
Copy link

spacem commented Nov 30, 2017

I had this happen a while ago but enabling tcp/ip seemed to fix it but now I cannot connect again and I cant figure out why. Tcp seems to be enabled in configuration manager. Please am I doing something wrong?

As a feature request it would be good to have better feedback if we are doing this wrong or if possible to make tedious use the same logic to connect as sql-server management studio.

This is with sql-server express 2008r2, tedious@2.1.5

var Connection = require('tedious').Connection;
var config = {
  userName: 'myuser',
  password: 'password',
  server: 'localhost',
  options: {
      database: 'testdb',
      instanceName: 'sqlexpress'
  }
}
var connection = new Connection(config);
connection.on('connect', function(err) {
  if (err) {
    console.log(err);
  } else {
    console.log('Connected');
  }
});
{ ConnectionError: Failed to connect to localhost:undefined in 15000ms
    at ConnectionError (C:\work\sqltest\node_modules\tedious\lib\errors.js:12:12)
    at Connection.connectTimeout (C:\work\sqltest\node_modules\tedious\lib\connection.js:789:28)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
  message: 'Failed to connect to localhost:undefined in 15000ms',
  code: 'ETIMEOUT' }

image

^ this works fine

@Suraiya-Hameed
Copy link
Member

options.instanceName
The instance name to connect to. The SQL Server Browser service must be running on the database server, and UDP port 1444 on the database server must be reachable.

@spacem since you're using options.instanceName, can you double check the above conditions? If those are not satisfied, try using options.port instead.

Failed to connect is a generic error, you can notice almost similar messages in other database drivers too, if instance or port is wrong. Error message with more useful details are available only after connection succeeds, as driver doesn't have much detail before that 😅

@spacem
Copy link
Author

spacem commented Nov 30, 2017

Thanks so much - it was just the SQL Server Browser service was not started. I guess management studio must do some magic when connecting to localhost.

@spacem spacem closed this as completed Nov 30, 2017
@sachinmishra007
Copy link

Tedious Connect basically looking for the SQL Server Browser and SQL Server Agent mode to be on with TCP Enabled optioned for the Protocols.

So if any of the service or port is disabled then It prompts for timeout exception

@xinthose
Copy link

xinthose commented Apr 9, 2020

I followed the directions on this SO answer and it worked for me:

  • Enable and Start SQL Server Browser
  • Enable TCP/IP Protocol for SQLEXPRESS
    • You can run SQL Server Configuration Manager with one of the commands listed on this page.
      Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants