I am using KnexJs attempting to connect to a local Microsoft SQL Server Express. However, with the below configuration, I am getting an error. I've followed the typical steps, but I'm still getting the error.
What I've tried:
Configuration / query code:
let mssql = knex({
client: 'mssql',
connection: {
host: 'localhost\\sqlexpress',
user: 'test',
password: 'test',
database: 'AdventureWorks2017',
// port:1433,
// options: {
// trustedConnection: true
// },
useNullAsDefault: true
}
});
mssql.raw('select 1 as result').then(function (result) {
console.log('result');
console.log(result);
mainWindow.webContents.send('testConnectionResponse', result === 1);
event.sender.send('testConnectionResponse', result === 1);
}).catch(function (err) {
console.log(err);
mainWindow.webContents.send('query-error', err);
}).finally(() => {
mssql.destroy();
});
Error:
ConnectionError: Failed to connect to localhost:undefined in 15000ms
It turns out that I also needed to enable the SQL Server Browser windows service like so:
Success!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With