const databasePath = 'C:\\Users\\2250689\\Downloads\\trailRMTool.accdb';
const connection = odbc.connect(`Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=${databasePath}`, (err) => {
if (err) {
console.error('Error connecting to the database:', err);
return;
}
const sqlQuery = 'SELECT Name FROM RMData';
connection.query(sqlQuery, (queryError, result) => {
if (queryError) {
console.error('Error executing query:', queryError);
} else {
console.log('Query result:', result);
}
connection.close((closeError) => {
if (closeError) {
console.error('Error closing the database connection:', closeError);
} else {
console.log('Database connection closed.');
}
});
});
});
it is also showing that there is an error in node_modules file also, I tried querying one column as well but nothing worked
The problem is that you are trying to access
connection
object but it's undefined, because you are using callback API when callingodbc.connect((err) => {})
.To solve the problem:
a) Use async/await API instead of callback API
b) Remove initialisation of const connection and add agrument
connection
in the callback. Code: