Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Error: No connection is specified for that request; while connecting to Sql server using express.js? #89

Open
hunaynrestarted opened this issue Feb 12, 2019 · 1 comment

Comments

@hunaynrestarted
Copy link

I am using the latest versions of node, express and mssql module. I am trying to connect to the local instance of sql server 2014 using express.js.

I am using mssql module and callbacks mechanism from the official documentation.

I have tried:

const express= require('express');
const app= express();
const mssql= require('mssql');

app.get('/', (req, res) => 
{
  const configuration=
  {
    name: "default",
    host: 'localhost',
    database: 'HimHer',
    user: '',
    password: '',
    port: 1433
  }
 
        new mssql.connect(configuration, error => 
        {
            new mssql.Request().query('Select * from Users', (err, dataset) => 
            {   
                  if(err)
                  {
                      console.log(err);
                      res.send(err);  
                      return;
                  }
                  else
                  {
                      console.dir(dataset);  
                      res.send(JSON.stringify(dataset));  
                      return;           
                  }

             
         });
    });

    mssql.close();
    
 
    mssql.on('error', err => 
    {
        console.log(err);  
    });
});



app.listen(5000, () => 
{
    console.log('Listening to requests on port 5000');
})

I want it to be connected to the database but it throws error:

{"code":"ENOCONN","name":"RequestError"}

@s1sads1
Copy link

s1sads1 commented Jan 18, 2021

YOU CAN TRY THIS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants