Skip to content

Error: Code: -2001 Msg: Invalid Object #29

@miljosh68

Description

@miljosh68

Node: v10.7.0
Express: v4.16.3
sqlanywhere: v1.0.23

Trying my hands on Node, Express and SQL AnyWhere. The database server is running SQL AnyWhere version 12 in network mode running on a PC named 'server2' listening on port '2639' (not the default 2638 port).

The 'index.html' submits form using ajax to '/showrptlist' route which uses the project ID in the SQL and tries to retrieve data from the database. But, in the console, I get "Error: Code: -2001 Msg: Invalid Object" error. Earlier I was able to display the result in the web page but now, I get the above error all the time.

How to fix it and display the data in the web page?

Here is code from my index.js.

const express = require('express');
const app = express();
const path = require('path');

app.set('view engine', 'pug');
app.set("views", path.join(__dirname, "./views"));
app.use(express.static(path.join(__dirname, './public')));

const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

const sqla = require('sqlanywhere');
const conn = sqla.createConnection();
conn_params = {
    Host: 'server2:2639',
    UserId: '*****',
    Password: '*****', 
    DatabaseName: '*****'
};

conn.connect(conn_params, function(err) {
    if (err) {
        console.log('A Database Error has occured while connecting.')
    } else {
        console.log('Database connection successful!');
    }
});

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname + '/index.html'));
});
app.post('/showrptlist', function(req, res) {
    conn.exec("SELECT wr.col1 + ' - ' + wr.col2 + ' - ' +  wr.col3 + ' - ' + wr.col4  'test_number', wr.col1, wr.col2, wr.col3, wr.col4, wr.web_report_name, wr.rpt_descr, wr.prjnum, prfx.prfx_desc FROM mtl_webreports wr left outer join mtl_test_prfx prfx on wr.test_id = prfx.prfx WHERE wr.prjnum =  ?  ORDER BY wr.col4 desc, wr.col1 asc, wr.col2 asc, wr.col3 asc", [req.body.txtProj], function (err, rows) {
        if (err) {
            console.log('Could not search verified reports. ' + err);
        } else {
            res.send(rows);
        }
    });
});

app.use(function (req, res, next) {
    res.status(404).send("Sorry, can't find that!")
})

app.listen(3000, () => console.log('Listening on port 3000'));

if (conn.connected()) {
    conn.disconnect();
    console.log('Disconnected from Database.');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions