TimelordUK / node-sqlserver-v8

branched from node-sqlserver, SQL server driver compatible with all versions of Node
Other
139 stars 43 forks source link

[Question] What is the authentication detail if set trustedConnection to be true? #323

Open Gong-Allen opened 5 months ago

Gong-Allen commented 5 months ago

After reading some documentation I know I can use below configuration to enable Windows Authentication

var config = {
    driver: "msnodesqlv8",
    server: "localhost",
    database: "MyDatabase",
    options: {
        trustedConnection: true
    },
};

So what is the authentication protocol for this Windows Authentication? Thanks.

TimelordUK commented 5 months ago

i would not use this, simply use a connection string

const mssql= require('mssql/msnodesqlv8')
const {runQuery} = require("./query");
const connectionString  = "Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\\node;Database=scratch;Trusted_Connection=yes;"

async function runner() {
    const res = await runQuery(mssql, connectionString, 'select top 3 * from syscolumns')
    console.log(JSON.stringify(res, null, 4))
}

runner().then(() => {
    console.log('done')
})

query.js

async function runQuery(mssql, connectionString, sqlString) {
    const config = {
        connectionString: connectionString
    }

    const pool = await mssql.connect(config)
    const res = await pool.query(sqlString)
    await pool.close()
    return res
}

exports.runQuery = runQuery
Gong-Allen commented 5 months ago

Hi @TimelordUK , Thanks for your response, but I am not asking how to use Windows Authentication, I am asking the protocol of this Windows Authentication, is it Kerberos?