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

拟墨画扇 提交于 2020-12-06 12:10:10

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/49185969/connectionerror-failed-to-connect-to-localhostundefined-in-15000ms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!