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, [email protected]
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' }
^ this works fine
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 馃槄
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.
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
Most helpful comment
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.