使用mssql连接Dataverse执行查询

54 阅读1分钟

使用mssql连接Dataverse执行查询

const sql = require('mssql');

async function connectWithMssql() {
    const config = {
        server: 'xxx.com', //环境地址
        database: 'xxx15310', //数据库
        port: 1433,
        options: {
            requestTimeout: 15000 * 10,
            connectTimeout: 15000 * 10,
            encrypt: true, // for azure
            trustServerCertificate: false // change to true for local dev / self-signed certs
        },
        pool: {
            max: 10,
            min: 0,
            idleTimeoutMillis: 30000
          },
        authentication: {
            type: 'azure-active-directory-service-principal-secret',
            options: {
                clientId: 'xxx-001-001',
                tenantId: 'xxx-aa046',
                clientSecret: 'xxx-ww-r'
            }
        }
    };

    try {
        const pool = await sql.connect(config);
        const result = await pool.request()?.query(`select * from account`)
        console.log(result)
        return pool;
    } catch (err) {
        console.error('SQL连接错误:', err);
        throw err;
    }
}

connectWithMssql()