1

I need t o provide the SQL connection (using the library called mssql) for modules, so I provide the code like this:

var config = {
    server: "149.xxx.xx.x",
    database: "Database",
    user: "User",
    password: "Password",
    connectionTimeout: 300000,
    requestTimeout: 300000,
    pool: {
        idleTimeoutMillis: 300000,
        max: 100
    }
};

function getEmp() {
    var connection = new sql.Connection(config);
    var req = new sql.Request(connection);

    connection.connect(function (error) {
        if(error) {
            console.log(error);
            return;
        }
        req.query('Procedure', function(err, data) {
            if (err) {
                console.log(err);
            } else {
                console.log(data);
            }
            connection.close();
        });
    });
}

getEmp();` 

and I receive the error:

 { ConnectionError: Failed to connect to 149.xxx.xx.x:1433 - connect
ETIMEDOUT 149.xxx.xx.x:1433 at Connection.<anonymous>
(/Users/xx/Learning/NodeJS/srv-express/node_modules/mssql/lib/tedious.js:353:25)
at Connection.g (events.js:292:16) at emitOne (events.js:96:13) at
Connection.emit (events.js:188:7) at Connection.socketError
(/Users/xx/Learning/NodeJS/srv-express/node_modules/tedious/lib/connection.js:791:12)
at Socket.<anonymous>
(/Users/xx/Learning/NodeJS/srv-express/node_modules/tedious/lib/connection.js:33:15)
at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at
emitErrorNT (net.js:1277:8) at _combinedTickCallback
(internal/process/next_tick.js:80:11)


name: 'ConnectionError',   message: 'Failed to connect to
49.xxx.xx.x:1433 - connect ETIMEDOUT 149.xxx.xx.x:1433',   code: 'ESOCKET' }

For sure the data are correct- DataGrip is connecting fine here.

I found at google the similar problem, the problem was Disabled TCP/IP. I checked this one and it's Enabled with this port 1443.

The TCP/IP, Named Pipes and Shared Memory is Enabled.

TCP Dynamic Ports: 1443 TCP Port: empty

23
  • to what port do you try to connect, 1433 or 1443? Commented Jul 17, 2017 at 10:08
  • The post is default port 1433, now I see it was bad. On PORT: 1443, I have the error: { ConnectionError: Login failed for user 'User'. name: 'ConnectionError', message: 'Login failed for user \'User\'.', code: 'ELOGIN' } Commented Jul 17, 2017 at 10:13
  • This means at least the port is correct, you reached the server, but have another problem. Check sql server errorlog to find out the exact reason of "login failed" Commented Jul 17, 2017 at 10:15
  • I check the logs: Error: 18456, Severity: 14, State: 38. Login failed for user 'User'. Reason: Failed to open the explicitly specified database 'Database Name'. [CLIENT: MYIP] Commented Jul 17, 2017 at 10:28
  • is the 'Database Name' online? Commented Jul 17, 2017 at 10:29

1 Answer 1

3

To find the reason of 18456 error "login failed for user..." one should check SQLServer error log.

In case of

Reason: Failed to open the explicitly specified database 'Database Name'

one should first check the state of the database, if it's online, like this:

 select name, 
       user_access_desc, 
       state_desc 
 from sys.databases where name='yourDatabase'

In case the database is online, the next step is to check is the user can access the database (if it's mapped to the database:)

 select * 
 from yourDB.sys.database_principals 
 where name = 'YourUserName';

This code is valid for checking existance of user corresponding to sql server login only (windows login can access the server using windows group login, so does the user)

In case the user does not exists we should create user for this login and give him appropriate permissions. Here is the link for user cteation CREATE USER (Transact-SQL)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.