sparrowrice
sparrowrice

Reputation: 1

Unable to connect to SQL Server database using mssql and expressjs

I am trying to connect to a SQL Server database from expressjs using mssql, but I keep getting this:

error

I am following the example from https://www.npmjs.com/package/mssql#connections-1

The code in my app.js is as follows

const config = {
    //user: '',
    //password: '',
    server: 'LAPTOP-A7INMDKJ',
    database: 'dbone'
}   

sql.on('error', (err)=> {
    // error handler
});
sql.connect(config).then(
    (pool) =>{
        return pool.request()
                    .query('select * from course');
    }).
    then(result=> {
        console.log('dasdasdsa');
        console.log(result);
    }).
    catch( (err)=>{
        console.log(err);
    });

I Component services I have this

Component services  screenshot

and in computer management tcp/ip is enabled

computer management screenshot

What am I doing wrong? I am using Windows authentication for SQL Server.

Upvotes: 0

Views: 292

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89396

The normal troubleshooting process is to verify:

  1. SQL Server has TCP/IP enabled and is configured to listen on port 1433 in Configuration Manager.
  2. SQL Server is running and the SQL Server Error log has an entry like Server is listening on [ 'any' <ipv4> 1433].
  3. The Windows Firewall is not blocking inbound TCP connections on port 1433
  4. The client can resolve the SQL Server's hostname correctly
  5. The client can connect over TCP/IP to port 1433 on the SQL Server, eg by powershell's Test-NetConnection -ComputerName [sqlserverhostname] -Port 1433

Upvotes: 1

Related Questions