KamSami
KamSami

Reputation: 407

How to use Windows authentication to connect to Sql express?

I have a .env file that contains the below and I am using tedious connection pool.

SQL_SERVER=localhost
SQL_UNAME=US\JENNY
SQL_PSWD=Windows password
SQL_DB=DatabaseName

But I am getting login failed error as shown below:

ConnectionError: Login failed for user 'US\JENNY'

Below is my dbconfig file

const dotenv = require('dotenv');
dotenv.config();

module.exports = {
    userName: process.env.SQL_UNAME,
    password: process.env.SQL_PSWD,
    server: process.env.SQL_SERVER,
    options: {
        instanceName: 'SQLEXPRESS',
        encrypt: false,
        database: process.env.SQL_DB,
        rowCollectionOnDone: true,
        useColumnNames: true // for easier JSON formatting
   }
};

Upvotes: 0

Views: 1833

Answers (1)

clockwatcher
clockwatcher

Reputation: 3363

Not sure what version of Tedious you're using. I bring it up because userName and password have been moved into an authentication section, so your current config would get you a deprecation warning.

But if you are using a current version, the authentication section also has an authentication.type setting that you can set to ntlm. See http://tediousjs.github.io/tedious/api-connection.html#function_newConnection for details.

The following connection config works for a windows based login for me:

module.exports = {
    server: process.env.SQL_SERVER,
    options: {
        instanceName: 'SQLEXPRESS',
        encrypt: false,
        database: process.env.SQL_DB,
        rowCollectionOnDone: true,
        useColumnNames: true
    },
    authentication: {
        type: 'ntlm',
        options: {
            userName: process.env.SQL_UNAME,
            password: process.env.SQL_PSWD,
            domain: process.env.SQL_DOMAIN
        }
    }
}

Upvotes: 3

Related Questions