Thursday, 27 April 2017

I need help understanding my bug with mssql and nodejs

So this is how i created my connection. Keep in mind config.mssql is inside my config.js file in which i have all the connection properties i need to use like database username port and password

var connection = new sql.connect(config.mssql);
    var request = new sql.Request(connection);
    request.query('Insert into Campionamento_Contratto (Camp_Nome,Camp_Cognome,Camp_TelFisso,Camp_Cellulare,Camp_Note, Camp_UserInsert) values ('+req.body.campNome+','+req.body.campCognome+','+req.body.campTel+','+req.body.campCel+','+ req.body.campNote+','+req.user.username+')',
        function(err) {
            if (err) {
                console.log(err);
            }
            console.log(connection);
            res.redirect(301, '/home');

        }
    );

And this are my logs. So i would really appriciate if u would help me with a solution> Thanks in advance.

green-camp-7 { ConnectionError: Connection is closed.
green-camp-7     at ConnectionError (/opt/green-camp/node_modules/mssql/lib/base.js:1428:7)
green-camp-7     at Request._query (/opt/green-camp/node_modules/mssql/lib/base.js:1300:37)
green-camp-7     at Request._query (/opt/green-camp/node_modules/mssql/lib/tedious.js:497:11)
green-camp-7     at Request.query (/opt/green-camp/node_modules/mssql/lib/base.js:1243:12)
green-camp-7     at /opt/green-camp/routes/home.js:21:13
green-camp-7     at Layer.handle [as handle_request] (/opt/green-camp/node_modules/express/lib/router/layer.js:95:5)
green-camp-7     at next (/opt/green-camp/node_modules/express/lib/router/route.js:137:13)
green-camp-7     at isAuthenticated (/opt/green-camp/middleware/isAuthenticated.js:8:16)
green-camp-7     at Layer.handle [as handle_request] (/opt/green-camp/node_modules/express/lib/router/layer.js:95:5)
green-camp-7     at next (/opt/green-camp/node_modules/express/lib/router/route.js:137:13)
green-camp-7     at Route.dispatch (/opt/green-camp/node_modules/express/lib/router/route.js:112:3)
green-camp-7     at Layer.handle [as handle_request] (/opt/green-camp/node_modules/express/lib/router/layer.js:95:5)
green-camp-7     at /opt/green-camp/node_modules/express/lib/router/index.js:281:22
green-camp-7     at Function.process_params (/opt/green-camp/node_modules/express/lib/router/index.js:335:12)
green-camp-7     at next (/opt/green-camp/node_modules/express/lib/router/index.js:275:10)
green-camp-7     at Function.handle (/opt/green-camp/node_modules/express/lib/router/index.js:174:3)
green-camp-7     at router (/opt/green-camp/node_modules/express/lib/router/index.js:47:12)
green-camp-7     at Layer.handle [as handle_request] (/opt/green-camp/node_modules/express/lib/router/layer.js:95:5)
green-camp-7     at trim_prefix (/opt/green-camp/node_modules/express/lib/router/index.js:317:13)
green-camp-7     at /opt/green-camp/node_modules/express/lib/router/index.js:284:7
green-camp-7     at Function.process_params (/opt/green-camp/node_modules/express/lib/router/index.js:335:12)
green-camp-7     at next (/opt/green-camp/node_modules/express/lib/router/index.js:275:10) code: 'ECONNCLOSED', name: 'ConnectionError' }
green-camp-7 Promise {
green-camp-7   <rejected> TypeError: Invalid server: undefined
green-camp-7     at new Connection (/opt/green-camp/node_modules/tedious/lib/connection.js:71:13)
green-camp-7     at base.Promise (/opt/green-camp/node_modules/mssql/lib/tedious.js:212:23)
green-camp-7     at ConnectionPool._poolCreate (/opt/green-camp/node_modules/mssql/lib/tedious.js:177:12)
green-camp-7     at ConnectionPool._connect (/opt/green-camp/node_modules/mssql/lib/base.js:241:10)
green-camp-7     at PromiseLibrary (/opt/green-camp/node_modules/mssql/lib/base.js:217:19)
green-camp-7     at ConnectionPool.connect (/opt/green-camp/node_modules/mssql/lib/base.js:216:12)
green-camp-7     at new connect (/opt/green-camp/node_modules/mssql/lib/base.js:1600:27)
green-camp-7     at Object.<anonymous> (/opt/green-camp/routes/home.js:7:18)
green-camp-7     at Module._compile (module.js:541:32)
green-camp-7     at Object.Module._extensions..js (module.js:550:10)
green-camp-7     at Module.load (module.js:458:32)
green-camp-7     at tryModuleLoad (module.js:417:12)
green-camp-7     at Function.Module._load (module.js:409:3)
green-camp-7     at Function._load (/root/.nvm/versions/node/v6.3.1/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
green-camp-7     at Module.require (module.js:468:17)
green-camp-7     at require (internal/module.js:20:19)
green-camp-7     at Object.<anonymous> (/opt/green-camp/app.js:43:12)
green-camp-7     at Module._compile (module.js:541:32)
green-camp-7     at Object.Module._extensions..js (module.js:550:10)
green-camp-7     at Module.load (module.js:458:32)
green-camp-7     at tryModuleLoad (module.js:417:12)
green-camp-7     at Function.Module._load (module.js:409:3) }



via Ardit Kurti

No comments:

Post a Comment