Connection error in Sequelize,Postgres,Nodejs - node.js

LOG:
///////////////
reject(new sequelizeErrors.ConnectionError(err));
^
ConnectionError [SequelizeConnectionError]: password authentication failed for user "postgres"
at Client._connectionCallback (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:142:24)
at Client._handleErrorWhileConnecting (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg/lib/client.js:305:19)
at Client._handleErrorMessage (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg/lib/client.js:325:19)
at Connection.emit (node:events:513:28)
at /home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg/lib/connection.js:114:12
at Parser.parse (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket. (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9) {
parent: error: password authentication failed for user "postgres"
at Parser.parseErrorMessage (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/home/rishikesh/Desktop/Bug_tracker_test_1/Bug_Tracker_TOOL/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
///////////////sequelize
const {Sequelize,DataTypes} = require('sequelize');
const Upload_Model = require('./excel_upload_model');
const sequelize = new Sequelize('BugTracker','postgres','',{
host:'localhost',
dialect:'postgres'
});
const Sequelize_model = Upload_Model(sequelize,Sequelize);
sequelize.sync()
.then(()=>{
console.log(Database is ready)
})
module.exports = {
Sequelize_model
}
///////////// models
module.exports=(sequelize,DataTypes)=>{
return sequelize.define('excel_upload_model',{
id:{
type:DataTypes.INTEGER,
required:true,
primaryKey: true
},
unique_name:{
type:DataTypes.STRING,
},
enter code here
filename:{
type:DataTypes.STRING,
}
})
}

Related

ELOGIN error while connecting to the SQL server

I'm learning full stack web development and was trying to connect to SQL server from my backend Node.js. I was following an online video. While running the index.js file I get the below error -
ConnectionError: Login failed for user 'systemadmin'.
at C:\Users\akunjalw\Desktop\FullStack\server\node_modules\mssql\lib\tedious\connection-pool.js:70:17
at Connection.onConnect (C:\Users\akunjalw\Desktop\FullStack\server\node_modules\tedious\lib\connection.js:1038:9)
at Object.onceWrapper (node:events:640:26)
at Connection.emit (node:events:520:28)
at Connection.emit (C:\Users\akunjalw\Desktop\FullStack\server\node_modules\tedious\lib\connection.js:1066:18)
at Parser.<anonymous> (C:\Users\akunjalw\Desktop\FullStack\server\node_modules\tedious\lib\connection.js:2574:20)
at Object.onceWrapper (node:events:639:28)
at Parser.emit (node:events:520:28)
at Readable.<anonymous> (C:\Users\akunjalw\Desktop\FullStack\server\node_modules\tedious\lib\token\token-stream-parser.js:32:12)
at Readable.emit (node:events:520:28) {
code: 'ELOGIN',
originalError: ConnectionError: Login failed for user 'systemadmin'.
at Login7TokenHandler.onErrorMessage (C:\Users\akunjalw\Desktop\FullStack\server\node_modules\tedious\lib\token\handler.js:239:19)
at Readable.<anonymous> (C:\Users\akunjalw\Desktop\FullStack\server\node_modules\tedious\lib\token\token-stream-parser.js:26:33)
at Readable.emit (node:events:520:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Readable.push (node:internal/streams/readable:228:10)
at next (node:internal/streams/from:98:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ELOGIN',
isTransient: undefined
}
}
undefined
[nodemon] clean exit - waiting for changes before restart
The code is as follows
const sql = require("mssql");
const config = {
user: "systemadmin",
password: "R#jasthaan1212",
server: "localhost",
database: "ORG_EMPLOYEEDATA",
options: {
trustedconnection: true,
trustServerCertificate: true,
enableArithAbort: true,
instancename: "SQL2019",
},
port: 50685,
};
async function getEmployeeName() {
try {
let pool = await sql.connect(config);
let employeeData = await pool
.request()
.query("select * from dbo.EMPLOYEES_DATA");
return employeeData.recordsets;
} catch (error) {
console.log(error);
}
}
module.exports = { getEmployeeName: getEmployeeName };
const dboperations = require("./dboperations");
dboperations.getEmployeeName().then((result) => {
console.log(result);
});
Please let me know what exactly I'm missing here. I couldn't find the way to resolve this by searching in internet as well, may be I'm terrible at searching. Any help to resolve this is appreciated.

How do I use Sequelize to connect to Heroku Postgres?

this is my configuration:
import { Sequelize } from "sequelize";
import dotenv from 'dotenv';
dotenv.config();
export const sequelize = new Sequelize(process.env.DATABASE_URL as string,
{
dialect: 'postgres',
}
)
error:
ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "186.194.175.39", user "xuavcbfkstvqrm", database "d3t76co8ov8vqm", SSL off
at Client._connectionCallback (d:\Projetos-VSCODE\Crud-tsnode\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:189:24)
at Client._handleErrorWhileConnecting (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg\lib\client.js:305:19)
at Client._handleErrorMessage (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg\lib\client.js:325:19)
at Connection.emit (node:events:390:28)
at Connection.emit (node:domain:475:12)
at d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg\lib\connection.js:114:12
at Parser.parse (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:104:9)
at Socket.<anonymous> (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\index.ts:7:48)
at Socket.emit (node:events:390:28)
at Socket.emit (node:domain:475:12) {
parent: error: no pg_hba.conf entry for host "186.194.175.39", user "xuavcbfkstvqrm", database "d3t76co8ov8vqm", SSL off
at Parser.parseErrorMessage (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:369:69)
at Parser.handlePacket (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:188:21)
at Parser.parse (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:103:30)
at Socket.<anonymous> (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\index.ts:7:48)
at Socket.emit (node:events:390:28)
at Socket.emit (node:domain:475:12)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:199:23) {
length: 168,
severity: 'FATAL',
code: '28000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'auth.c',
line: '496',
routine: 'ClientAuthentication'
},
original: error: no pg_hba.conf entry for host "186.194.175.39", user "xuavcbfkstvqrm", database "d3t76co8ov8vqm", SSL off
at Parser.parseErrorMessage (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:369:69)
at Parser.handlePacket (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:188:21)
at Parser.parse (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\parser.ts:103:30)
at Socket.<anonymous> (d:\Projetos-VSCODE\Crud-tsnode\node_modules\pg-protocol\src\index.ts:7:48)
at Socket.emit (node:events:390:28)
at Socket.emit (node:domain:475:12)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:199:23) {
length: 168,
severity: 'FATAL',
code: '28000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'auth.c',
line: '496',
routine: 'ClientAuthentication'
}
}
What is missing in my code to connect correctly?, doing this test and being able to connect to the postgresql database on heroku, I will upload the application and I believe that the CRUD that needs to access the route and add the user will work, but I have to do it this connection to the heroku database, but I'm not getting it

Unknown command when using promise-ftp in node

I'm trying to use a promise approach when interacting with my ftp server. I'm using the node package 'promise-ftp' v1.3.5.
The code I have is as follows:
const appFeedBuffer = Buffer.from('somedatastring', 'utf8');
var Client = require('promise-ftp');
var ftpClient = new Client();
ftpClient.connect({ host: 'myHost', user: 'me', password: 'mypassword' })
.then(() => {
return ftpClient.mkdir('newDir')
}).then(() => {
return ftpClient.put(appFeedBuffer, 'fileName')
}).then(()=> {
return ftpClient.rmdir('oldDir')
}).then(() => {
return ftpClient.rename('newDir', 'oldDir')
}).then(() => {
return ftpClient.end();
}).catch(err => {
console.log("something went wrong: " + err);
res.status(500).send('SERVER ERROR');
});
The problem is the put command - I get the error 'UNKNOWN COMMAND' which appears to come from the #icetee/ftp library, of which promise-ftp is a dependant. put is most certainly a valid command in the promise-ftp library!
Stack:
Unhandled rejection Error: Unknown command
at makeError (/Users/projects/ftpProject/node_modules/#icetee/ftp/lib/connection.js:1128:13)
at Parser.<anonymous> (/Users/projects/ftpProject/node_modules/#icetee/ftp/lib/connection.js:122:25)
at emitTwo (events.js:126:13)
at Parser.emit (events.js:214:7)
at Parser._write (/Users/projects/ftpProject/node_modules/#icetee/ftp/lib/parser.js:61:10)
at doWrite (_stream_writable.js:397:12)
at writeOrBuffer (_stream_writable.js:383:5)
at Parser.Writable.write (_stream_writable.js:290:11)
at Socket.ondata (/Users/projects/ftpProject/node_modules/#icetee/ftp/lib/connection.js:298:20)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
I can't find anyone else having this problem. What am I doing wrong?

trying to connect SQL using node js

app.get('/', function (req, res) {
var config = {
user: 'sa',
password: '',
server: 'localhost',
database: 'TestDB'
};
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from userInfo', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
console.log(recordset);
});
});
});
Getting this error in command prompt
{ Error: Failed to connect to localhost:1433 - Could not connect (sequence)
at Connection.tedious.once.err (D:\Nodejs\UsersCreate\node_modules\mssql\lib\tedious.js:216:17)
at Object.onceWrapper (events.js:293:19)
at emitOne (events.js:96:13)
at Connection.emit (events.js:191:7)
at Connection.socketError (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connection.js:875:14)
at D:\Nodejs\UsersCreate\node_modules\tedious\lib\connection.js:740:25
at SequentialConnectionStrategy.connect (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connector.js:153:9)
at Socket.onError (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connector.js:169:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
code: 'ESOCKET',
originalError:
{ ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at ConnectionError (D:\Nodejs\UsersCreate\node_modules\tedious\lib\errors.js:12:12)
at Connection.socketError (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connection.js:875:30)
at D:\Nodejs\UsersCreate\node_modules\tedious\lib\connection.js:740:25
at SequentialConnectionStrategy.connect (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connector.js:153:9)
at Socket.onError (D:\Nodejs\UsersCreate\node_modules\tedious\lib\connector.js:169:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at emitErrorNT (net.js:1284:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
message: 'Failed to connect to localhost:1433 - Could not connect (sequence)',
code: 'ESOCKET' },
name: 'ConnectionError' }
{ ConnectionError: Connection is closed.
at Request._query (D:\Nodejs\UsersCreate\node_modules\mssql\lib\base.js:1299:37)
at Request._query (D:\Nodejs\UsersCreate\node_modules\mssql\lib\tedious.js:497:11)
at Request.query (D:\Nodejs\UsersCreate\node_modules\mssql\lib\base.js:1242:12)
at D:\Nodejs\UsersCreate\app.js:118:17
at _poolCreate.then.catch.err (D:\Nodejs\UsersCreate\node_modules\mssql\lib\base.js:269:7)
at process._tickCallback (internal/process/next_tick.js:109:7) code: 'ECONNCLOSED', name: 'ConnectionError' }
undefined
Please help me on this error and need navigation to rectify this error

sequelize.js: Unhandled rejection SequelizeForeignKeyConstraintError

I am trying to insert/update data into a postgresql db using the following function:
var updateStudentDataAndReturn = function(req, res, { redirectLink: redirectLink, studentId: studentId }) {
models.Student.update({
firstName: req.body.firstName,
lastName: req.body.lastName,
phoneNumber: req.body.phoneNumber,
skypeUsername: req.body.skypeUsername,
typeOfStudent: req.body.typeOfStudent,
school: req.body.school,
expectedYearOfGraduation: req.body.expectedYearOfGraduation,
TeamId: req.body.TeamId
}, {
where: {
id: studentId
}
}).then(() => {
return models.StudentMajor.destroy({
where: {
StudentId: studentId
}
})
}).then(() => {
return models.StudentSchool.destroy({
where: {
StudentId: studentId
}
})
}).then(() => {
if (!Array.isArray(req.body.major)) {req.body.major = [req.body.major]};
return req.body.major.forEach((major) => {
return models.StudentMajor.create({
StudentId: studentId,
major: major
});
});
}).then(() => {
if (!Array.isArray(req.body.school)) {req.body.school = [req.body.school]};
return req.body.school.forEach((school) => {
return models.StudentSchool.create({
StudentId: studentId,
school: school
});
});
}).then(() => {
return res.redirect(redirectLink);
}).catch((err) => {
console.log('ERROR', err);
});
}
I've already looked at every other similar question I could find, but none of the solutions seem to work. I keep getting the following error.
Executing (default): INSERT INTO "StudentSchools" ("id","school","createdAt","updatedAt","StudentId") VALUES (DEFAULT,'sas','2017-07-22 00:41:49.763 +00:00','2017-07-22 00:41:49.763 +00:00',96) RETURNING *;
Unhandled rejection SequelizeForeignKeyConstraintError: insert or update on table "StudentMajors" violates foreign key constraint "StudentMajors_StudentId_fkey"
at Query.formatError (/Users/Prathmesh/UPennTrackerDB/node_modules/sequelize/lib/dialects/postgres/query.js:296:14)
at Result.<anonymous> (/Users/Prathmesh/UPennTrackerDB/node_modules/sequelize/lib/dialects/postgres/query.js:88:19)
at emitOne (events.js:96:13)
at Result.emit (events.js:188:7)
at Result.Query.handleError (/Users/Prathmesh/UPennTrackerDB/node_modules/pg/lib/query.js:163:8)
at Client.<anonymous> (/Users/Prathmesh/UPennTrackerDB/node_modules/pg/lib/client.js:188:26)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at TLSSocket.<anonymous> (/Users/Prathmesh/UPennTrackerDB/node_modules/pg/lib/connection.js:133:12)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:543:20)
Executing (default): SELECT "id", "email", "hash", "salt", "role", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."id" = 96;
Unhandled rejection SequelizeForeignKeyConstraintError: insert or update on table "StudentSchools" violates foreign key constraint "StudentSchools_StudentId_fkey"
at Query.formatError (/Users/Prathmesh/UPennTrackerDB/node_modules/sequelize/lib/dialects/postgres/query.js:296:14)
at Result.<anonymous> (/Users/Prathmesh/UPennTrackerDB/node_modules/sequelize/lib/dialects/postgres/query.js:88:19)
at emitOne (events.js:96:13)
at Result.emit (events.js:188:7)
at Result.Query.handleError (/Users/Prathmesh/UPennTrackerDB/node_modules/pg/lib/query.js:163:8)
at Client.<anonymous> (/Users/Prathmesh/UPennTrackerDB/node_modules/pg/lib/client.js:188:26)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at TLSSocket.<anonymous> (/Users/Prathmesh/UPennTrackerDB/node_modules/pg/lib/connection.js:133:12)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:543:20)
Any help would be much appreciated

Resources