Closed miljosh68 closed 5 years ago
I tried to reproduce this but was unable to make it fail. I had to guess at your database schema and added a row of test data but everything seemed to work as expected. Can you send me the schema for the two tables involved?
Thanks @gperrow-SAP. I am not sure under what circumstances it showed me the error. But, I was able to connect and was able to view the intended report list. But, for some reason, the 'conn.connected()' always returns 'false'. Do you know why? The console never shows the 'Disconnected from Database.' message.
That's the nature of asynchronous programming. Your program has called conn.connect() which is executed asynchronously (sort of on another thread). Similarly, app.listen() is executed asynchronously. When your main thread gets to the if( conn.connected() ) line, the connect() function hasn't run yet, so conn.connected() is false. You can do something like this to catch CTRL-C:
process.on( 'SIGINT', function() {
if (conn.connected()) {
conn.disconnect();
console.log('Disconnected from Database.');
}
process.exit( 1 );
});
That supplies node with a function to call when the SIGINT signal is received, i.e. when the user hits CTRL-C.
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.