question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not connect to the database

See original GitHub issue

Hi,

I am having problems creating a connection string that works.

Server version: SQL Server 2014 Express.

I can login to SQL Management Studio with the same credentials. Server name: (local)\SQLEXPRESS2014 User: test Pass: testtest

To login with nodejs i tried this:

var sql = require('mssql');

var config = {
  connectionString: 'Server=(local)\\SQLEXPRESS2014;Database=test-server;UID=test;PWD=testtest;',
};

var connection = new sql.Connection(config);
connection.connect(function(err) {
    console.log(err); // This is always getting hit
});

That however returns the following error:

{ [ConnectionError: Failed to connect to undefined:1433 - connect ECONNREFUSED 127.0.0.1:1433] name: ‘ConnectionError’, message: ‘Failed to connect to undefined:1433 - connect ECONNREFUSED 127.0.0.1:1433’, code: ‘ESOCKET’ }

Same error if i change the config to:

var connection = new sql.Connection({
    user: 'test',
    password: 'testtest',
    server: '(local)\\SQLEXPRESS2014', // or localhost\\SQLEXPRESS2014
    database: 'test-server'
});

Somehow it does not translate the connection correctly.

(My file only contains the first lines at the top to connect. Otherwise it’s completely empty. I wanted to get the connection to work before writing any other code.)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
snovak7commented, May 10, 2016

This is how you should do it, if you’re connecting to named instance. http://stackoverflow.com/questions/21204411/connect-to-sql-server-with-mssql-for-node-js

0reactions
snovak7commented, May 27, 2018

@harshavarun25 Yes, you need access to the server as well as to the database. encrypt option is only for the connection encryption, unrelated to the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot connect to a database | AppCode Documentation
Cannot connect to a database · Step 1. Check your network settings · Step 2. Check your connection properties · Step 3. Check...
Read more >
Error: 'Failed to connect to database' when attempting to ...
When attempting to connect to a backend MS SQL Server database you receive an error similar to 'Failed to connect to database'.
Read more >
Cannot connect to Database server (mysql workbench)
The problem is that MySQL server is not installed. · Enter "services.msc" on the Start menu search box. · Find MySQL service under...
Read more >
How to Fix the Error Establishing a Database Connection in ...
If everything seems to be correct, and WordPress still cannot connect to the database, then your database server (MySQL server) may be down....
Read more >
How to Fix Error Establishing a Database Connection Error
How to Fix Error Establishing a DB Connection Error · Method 1: Repair the Database · Method 2: Change Login Credentials · Method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found