Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConnectionError: Failed to connect to localhost:undefined in 15000ms

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:

  1. Set up a SQL Server authentication login for the database
  2. Enable SQL Server authentication on the server
  3. Enable TCP/IP on the server
  4. Restart the Windows services
  5. Restart the SQL Server through SQL Server Management Studio
  6. Verify ability to log in through SQL Server Management Studio

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

like image 249
alan Avatar asked Dec 19 '22 00:12

alan


1 Answers

It turns out that I also needed to enable the SQL Server Browser windows service like so:

  1. Navigate to "Services"
  2. Select "Properties" on "SQL Server Browser"
  3. Flip "Start up type" to "Automatic"
  4. Start the service

Success!

like image 122
alan Avatar answered Dec 20 '22 17:12

alan