使用 sequelize 连接到本地 SQL Server 数据库 [英] Connect to a local SQL Server db with sequelize

查看:139
本文介绍了使用 sequelize 连接到本地 SQL Server 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成 SQL Server 安装程序后,给定的连接字符串是 Server=localhost\MSSQLSERVER01;Database=master;Trusted_Connection=True;,这似乎是一种奇怪的格式,如果我尝试连接使用该连接字符串通过 sequelize 连接到数据库:

Having completed the SQL Server installer, the given connection string is Server=localhost\MSSQLSERVER01;Database=master;Trusted_Connection=True;, which seems like a strange format, and if I try to connect to the db with sequelize using that connection string:

var sequelize = new Sequelize(process.env.DB_STRING);

我收到错误:

TypeError: 无法读取 null 的属性替换"

TypeError: Cannot read property 'replace' of null

在新的续集(C:\Users\George\Source\Repos\TestProj\node_modules\sequelize\lib\sequelize.js:132:40)在对象.(C:\Users\George\Source\Repos\TestProj\models\index.js:13:21) 在Module._compile (module.js:570:32)

at new Sequelize (C:\Users\George\Source\Repos\TestProj\node_modules\sequelize\lib\sequelize.js:132:40) at Object. (C:\Users\George\Source\Repos\TestProj\models\index.js:13:21) at Module._compile (module.js:570:32)

推荐答案

基于这篇文章 你应该安装 sequelize-msnodesqlv8:

Based on this article you should install sequelize-msnodesqlv8:

var sequelize = new Sequelize({
  dialect: 'mssql',
  dialectModulePath: 'sequelize-msnodesqlv8',
  dialectOptions: {
    instanceName: 'MSSQLSERVER01',
    trustedConnection: true
  },
  host: 'localhost',
  database: 'master'
});

或者更好:

var sequelize = new Sequelize({
  dialect: 'mssql',
  dialectModulePath: 'sequelize-msnodesqlv8',
  dialectOptions: {
    connectionString: 'Server=localhost\MSSQLSERVER01;Database=master; Trusted_Connection=yes;'
  },
});

但是您不应该将默认数据库保留为 Master.请改用您的数据库名称.

But you should not leave default database as Master. Use your database name instead.

标记:

node mssql 客户端很多,sequelize 默认使用乏味,但作为纯 javascript,乏味的 缺乏对集成安全.msnodesqlv8 是一个客户端,它与本机 odbc 库.这允许使用集成安全性.它确实需要额外的二进制文件来部署,但幸运的是,msnodesqlv8 与最常见的二进制文件一起分发架构

There are many node mssql clients and sequelize defaults to using tedious, but being pure javascript,tedious lacks support for integrated security. msnodesqlv8 is a client that interfaces with a native odbc library. This allows integrated security to be used. It does require additional binaries to deploy, but fortunately, msnodesqlv8 is distributed with binaries for the most common architectures

您正在使用集成安全性,因此您需要处理该问题.

You are using integrated security, so you need to deal with that problem.

另见这个问题.

这篇关于使用 sequelize 连接到本地 SQL Server 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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