Reputation: 431
i tried the following code:
const config = {
server: 'localhost',
database: 'MyDB',
user: *userName*,
password: *password*
const dbPool = new sql.ConnectionPool(config, err => {
if (err)
console.log(err)
else
console.log("success")
})
i created on the SSMS a user and a login, and did logged in with it to make sure it works. i changed the authentication from windows to SQL server. what am i missing?
I keep get this error message:
Login failed for user 'userNamr'.,
Code: 'ELOGIN'
Upvotes: 3
Views: 187
Reputation: 339
Is this the package you are using.In that case, I believe you are missing the connect method which as taken from the docs.Also ELOGIN err comes when login fails
const pool = new sql.ConnectionPool({
user: '...',
password: '...',
server: 'localhost',
database: '...'
})
pool.connect(err => {
// ...
})
Upvotes: 0
Reputation: 61
I think you have entered a wrong username or a user that does not exist but here is the demonstration how you can connect node.js to sql.
PS: make sure you have npm install and proper module for the db engine.
const pg = require("pg"); //replace "pg" with whatever engine you are using such as mssql
const connectionString = {
user: 'username',
host: 'localhost',
database: 'testdb',
password: 'mypass',
port: 5432,
};
const client = new pg.Client(connectionString);
client.connect();
client.query(
'SELECT * from student;'
).then(
res => {
console.log(res.rows);
}).finally(() => client.end());
Upvotes: 1