0

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.

1
  • Try localhost or 127.0.0.1 as host; make sure MSSQL is turned on and listens throughout firewalls. Commented Jan 19, 2020 at 18:53

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.