2

I am setting up a database with customer data in SQLite 3.2.1 using Node.js in Javascript.

The error SQLITE_ERROR: no such table: T_KUNDENDATEN_DE keeps being returned. From the error I understand that the DB can be contacted. The SQL Query works and the variables vorname and nachname are correctly captured in the URL and passed to the db.all constructor. But it return the error. In debug-mode I cannot figure out what is going wrong here.

The table T_KUNDENDATEN_DE is not new and has data in it.

Any suggestions to resolve this issue?

URL used to call app.get('/cdata'. http://localhost:8000/cdata?vorname=ralf&nachname=ruf

[![Table & Database][1]][1]
// Create express app
var express = require("express")
var app = express()
var DateObj= new Date()
var sqlite3 = require('sqlite3');
var db = new sqlite3.Database('KundendatenJS.db');
// Server port
var HTTP_PORT = 8000 
// Start server
app.listen(HTTP_PORT, () => {
    console.log("Server running on port %PORT%".replace("%PORT%",HTTP_PORT))
});
// Root endpoint
app.get("/", (req, res, next) => {
    res.json({"message":"Ok" + " " + DateObj })
});

// API endpoints
app.get('/cdata', function(req, res){
    if(req.query.vorname  && req.query.nachname){
        db.all('SELECT * FROM T_KUNDENDATEN_DE WHERE UPPER(VORNAME) = UPPER(?) AND UPPER(NACHNAME)=UPPER(?)', [req.query.vorname,req.query.nachname], function(err, rows){
            if(err){
                res.send(err.message);

            }
            else{
                console.log("Return the customer data for: " + req.query.vorname + " " + req.query.nachname);
                res.json(rows);
            }
        });
    }
    else{
console.log("No data found")
    }
});

// Default response for any other request
app.use(function(req, res){
    res.status(404);
});```
3
  • 1
    can you access T_KUNDENDATEN_DE via mysql? mysql -u root -p -> password -> use MyDATABASE; describe T_KUNDENDATEN_DE; Commented Mar 27, 2020 at 14:15
  • I found the issue, thanks to your question, although I used the sqlite3 command line interface. It was unable to access the DB, because it was not referenced correctly. It could not find the path. Instead it created an empty DB named T_KUNDENDATEN_DE. And of course in this new DB it will not be able to find the table. I will mark this as answer because I found a few other references for the same type of question but they remained unanswered Commented Mar 27, 2020 at 14:50
  • 1
    yep, so please add an aswer below Commented Mar 27, 2020 at 15:03

1 Answer 1

11

I auto-answered this question thanks to the comment by @messerbill.

The error occurs because the DB-path is not referenced correctly. SQLite create a new database if it cannot find an existing one. Hence SQLite will find a DB but not a table. The error message is misleading because it seems to point to an internal connection error.

Solution: Look in your solution for the path where a database is created. This will help you set the right path in your solution.

Sign up to request clarification or add additional context in comments.

4 Comments

"Look into solution for path, to correct path on solution", can you clarify that last part? Where did you look into to update the solution?
A year later hard so explain exactly. But if the DB-path is not referenced correctly SQLite will create a new DB in the script location folder. You can run the command '''.databases''' to check where the DB should be located.
Thanks, in my case it was on the knexfile, in case this comments helps somebody
4 years later & faced the same issue. i was using drizzle orm with better-sqlite3 but my seed script did not include NODE_ENV=development so i was creating sqlite.prod.db & my generate & push commands were creating sqlite.dev.db which was the problem :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.