2
votes

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);

I get the error:

TypeError: Cannot read property 'replace' of null

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)

1

1 Answers

3
votes

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'
});

or perhaps better:

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

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

Mark this:

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.

See also this question.