如何在sequelize连接对象中设置应用程序名称? [英] How to set application name in sequelize connection object?

查看:143
本文介绍了如何在sequelize连接对象中设置应用程序名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:

我想在初始化新的sequalize对象时更改connection stringapplication name.根据此stackoverflow问题, DialectOptions的appName如下:

I want to change the application name of the connection string when initialize a new sequalize object. based on this stackoverflow question, I set the appName of dialectOptions as follows:

    let conn = new Sequelize(this.models.sequelize.config.database, this.models.sequelize.config.username,
                this.models.sequelize.config.password, {
                host: this.models.sequelize.config.host,
                dialect: this.models.sequelize.getDialect(),
                dialectOptions: {
                    appName: "userid=-2@gid=" + gid
                }
            });

问题:

当我执行类似以下代码的事务时,application name不会传递到SQL Server.当我监视SQL查询的执行时,下图显示Tedious已发送到应用程序名称.

When I execute a transaction like the following code, the application name does not pass to the SQL server. When I monitor the execution of SQL queries, the following picture shows that Tedious was sent to the application name.

交易代码:

    await conn.transaction(async t => {
                for(let i in this.collect){
                    let queryBuilder = this.collect[i];
                    let options = {replacements: queryBuilder.replacement, transaction: t};
                    if(queryBuilder.type === 'insert'){
                        options.type = conn.QueryTypes.INSERT;
                    }
                    let row = await conn.query(queryBuilder.query + ';select @@IDENTITY as id', options);
                    progressBar.update(parseInt(i) + 1);
                }

,SQL Profiler图片为:

and the SQL Profiler picture is:

如何正确设置Application Name?

推荐答案

您必须在options对象中设置appName,以便正确的语法

you must set appName in options object so correct syntax is

let conn = new Sequelize(this.models.sequelize.config.database, this.models.sequelize.config.username,
            this.models.sequelize.config.password, {
            host: this.models.sequelize.config.host,
            dialect: this.models.sequelize.getDialect(),
            dialectOptions: {
               options: {
                  appName: "userid=-2@gid=" + gid
               }
            }
        });

这篇关于如何在sequelize连接对象中设置应用程序名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆