简体   繁体   中英

Error ELIFECYCLE 3228369023 on attempted connection to SQL Server database using Node.js MSSQL

I'm working on setting up an API for a SQL Server Express database, I'm planning on using mssql in Node.js with express to receive requests and interact with the database. I have tried several approaches to connecting to the DB via node, and believe that the server (running locally) is found, but my node app is unable to connect with it.

The approaches I've made include various different forms of connection strings (some just strings as displayed below, and some attempts using a JSON object). Also, at first I only used the mssql package, but I later added in msnodesqlv8.

function connect(){
var sql = require("mssql/msnodesqlv8");

// config for your database
var connString = 'Driver={SQL Server Native Client 11.0};Server={DESKTOP-RJH9ERF\\SQLEXPRESS};Uid={DESKTOP-RJH9ERF\\Jake};Database={MAIC};Trusted_Connection={yes};'

// connect to your database
sql.connect(connString, 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 Events', function (err, recordset) {

        if (err) console.log(err)

        // send records as a response
        res.send(recordset);

    });
});
};

At first, there appeared to be an issue with a user not being recognized. On my more recent approaches to connecting, however, I am getting this error repeatedly.

20 error code ELIFECYCLE 21 error errno 3228369023 22 error maic-api@1.0.0 start: node server.js 22 error Exit status 3228369023

I have seen no additional information regarding what this error means and after some searches online it remains unclear what is causing this. Is anyone familiar with this error and what it might have to do with MSSQL in node?

Sorry for being late to the party, I just fixed the same error right now. What was happening on my side was that I was using a .env file to provide variables for the database connection configuration and since it is bad practice to commit your .env , I had it stored locally. When I switched to my laptop, the .env file was gone, and so were my DB_USER and DB_PASS environment variables (they were actually undefined ).

For some reason, I could only make the tedious logs appear by placing console.log('OK') right after the require which was causing the error, like below. My guess is that for some reason the error buffer was not getting flushed.

db-conn.js

require('dotenv').config
var Connection = require('tedious').Connection

var config = {
  server: process.env.DB_SERVER,
  options: {
    database: process.env.DB_NAME,
    trustServerCertificate: true,
    encrypt: true,
  },
  authentication: {
    type: "default",
    options: {
      userName: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
    },
  },
};

const connection = new Connection(config);

module.exports = connection;

server.js

const connection = require("./server/db-conn");
console.log('OK');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM