Search code examples
node.jsnode-mssql

Azure SQL with Node mssql giving strange error


Using the npm mssql documentation, I am executing:

try {
    let pool = await sql.connect("mssql://user:pass!@dbserver/db?encrypt=true");
    let result = await pool.request().query("select * from dbo.db1.tbl");
    console.dir(result);
  } catch (err) {
    console.log(err);
}

And I get this cryptic (when I google) error:

 { number: 40515,
        state: 1,
        class: 15,
        message: 'Reference to database and/or server name in \'dbo.db1.tbl\' is not supported in this version of SQL Server.',
        ...

Any suggestions?


Solution

  • So I needed to include square brackets and separate schema from db name in the query:

    let result = await pool.request().query("select * from [dbo].[db1.tbl]");