2

So I got a connection working using tedious but the options available in node-mssql for handling JSON are something really useful that I would like to have access to.

The documentation for node-mssql says you can pass an object with authentication settings that tedious would use and it will override the user/password properties but it's definitely not doing that. I can confirm because the error message comes back with the value for the user property.

Is there something wrong with the config object?

const sqlConfig = {
    server: process.env.SQL_SERVER,    
    database: process.env.DATABASE_NAME,
    user: "root.user",                    
    password: "password",       
    options:
    {
        encrypt: true,             
        authentication: {
            type: "azure-active-directory-password",                         
            options: {
                userName: "root.options.authentication.options.userName",                    
                password: "password"                    
                }
        },
    }
};
Stephanie
  • 151
  • 8

2 Answers2

1

Here's the example using node-mssql and azure-active-directory-password(supports Azure AD from tedious@4.1.0):

const config = {
    server: 'yoursqlserver.database.windows.net',
    database: 'yourdb',
    authentication: {
        type: "azure-active-directory-password",
        options: {
            userName: "bob@contoso.com",
            password: "password",
            }
        }
    }

Ref here:

  1. https://stackoverflow.com/a/58386825/10549281
  2. https://stackoverflow.com/a/56145320/10549281.
  3. https://github.com/tediousjs/tedious/issues/416#issuecomment-441364272
Leon Yue
  • 15,693
  • 1
  • 11
  • 23
  • I tried this but had the same problem, the userName property here is not being passed. Here is the actual config I used - the server being azure means the connection must be encrypted. `const sqlConfig = { server: process.env.SQL_SERVER, database: process.env.DATABASE_NAME, options: { encrypt: true }, authentication: { type: "azure-active-directory-password", options: { userName: "bob@contoso.com", password: "password", } } }` – Stephanie Apr 26 '21 at 13:58
0

So there are packages for mssql and node-mssql. I installed node-mssql but was working with the documentation for mssql. I am an idiot.

Thanks to everyone who looked at this and especially Leon.

Stephanie
  • 151
  • 8