tedious icon indicating copy to clipboard operation
tedious copied to clipboard

ConnectionError: Login failed for user 'MyUser'

Open filipbahnan opened this issue 5 years ago • 10 comments

Hello, I have a Microsoft SQL server on my laptop and Im trying to connect to it but It just keeps giving me login failed. This is what my code looks like

var Connection = require('tedious').Connection;
var Request = require('tedious').Request;

var config = {
    server: "localhost",
    authentication: {
        type: "default",
        options: {
            userName: "MyUser",
            password: "pass"
        }
    }
};

var connection = new Connection(config);

I dont know why this is happening, please help :)

filipbahnan avatar Feb 21 '20 11:02 filipbahnan

Did you enable TCP/IP connections? They're disabled by default. Can you connect using another tool (e.g. SQL Server Management Studio)?

arthurschreiber avatar Feb 21 '20 11:02 arthurschreiber

Did you enable TCP/IP connections? They're disabled by default. Can you connect using another tool (e.g. SQL Server Management Studio)?

Yes I have enabled it and SQL server management studio works fine with the database

filipbahnan avatar Feb 21 '20 13:02 filipbahnan

Hi @filipanton, you could also double-check the user account that you were using for the connection is enabled for the server? Just wondering, which login method were you using for the server within the SQL server management studio?

MichaelSun90 avatar Feb 21 '20 17:02 MichaelSun90

Hi @filipanton, you could also double-check the user account that you were using for the connection is enabled for the server? Just wondering, which login method were you using for the server within the SQL server management studio?

Im not sure I understand what you mean.

All I did was "CREATE USER MyUser WITH PASSWORD = 'pass';" in the management studio and then give it all privileges. If I click on the database in the management studio and then security > users, the MyUser user shows up in the list.

filipbahnan avatar Feb 22 '20 13:02 filipbahnan

@filipanton What's the port for your SQL Server? You can check in SSMS:

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on' 
GO

And then set the port in the options under your config that the above sql command gives, like:

{
    "config": {
        "server": "localhost",
        "authentication": {
            "type": "default",
            "options": {
                "userName": "xxx",
                "password": "xxx"
            }
        },
        "options": {
            "port": 60543,
            "database": "master"
        }
    }
}

In my case, the default port 1433 didn't work, so using my SQL Server's specific port allowed me to gain access. Hopefully that works for you also?

IanChokS avatar Mar 03 '20 23:03 IanChokS

Hi @filipanton, you could also double-check the user account that you were using for the connection is enabled for the server? Just wondering, which login method were you using for the server within the SQL server management studio?

I used the windows login for the database, and i couldn't connect using tedious on NodeJS app!! what should I do ?

EG-DEV5 avatar Feb 06 '22 08:02 EG-DEV5

Hi @EG-DEV5, if you do not own the data base and you are not on NodeJS 17, then you can use out NTLM authentication type wich allows you to provide you window credential for logging in.

config = {
  server: "localhost",
  authentication: {
 	type: "ntlm",
 	options: {
 		domain: "<Windows user domain>",
 		userName: "<Windows user name>",
 		password: "<Windows user password>",
 		intanceName: "<SQL server instance name>"
 	}
   },
}

If you own the SQL Server instance, then you can easily create a user using SQL Server Management Studio, then use that user for logging via tedious default authentication.

MichaelSun90 avatar Feb 07 '22 17:02 MichaelSun90

What about if someone tries with a windows login,?, Then how to do that? instead of using specific user login in the SQL server.

erpramod avatar Oct 07 '22 16:10 erpramod

Hi @erpramod , unfortunately, tedious does not support windows login yet. If you can only work with windows login then may be this comment can help you: https://github.com/tediousjs/node-mssql/issues/1270#issuecomment-878363118. We will also look into the window login support on our side as well.

MichaelSun90 avatar Oct 11 '22 17:10 MichaelSun90

@filipanton What's the port for your SQL Server? You can check in SSMS:

USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on' 
GO

And then set the port in the options under your config that the above sql command gives, like:

{
    "config": {
        "server": "localhost",
        "authentication": {
            "type": "default",
            "options": {
                "userName": "xxx",
                "password": "xxx"
            }
        },
        "options": {
            "port": 60543,
            "database": "master"
        }
    }
}

In my case, the default port 1433 didn't work, so using my SQL Server's specific port allowed me to gain access. Hopefully that works for you also?

That worked for me!

realtytexas avatar Aug 09 '23 02:08 realtytexas