6

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 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

15 Comments

Thanks! Hmm I am getting issue Unhandled rejection SequelizeConnectionError: [Microsoft][SQL Server Native Client 11.0]Invalid value specified for connection string attribute 'Trusted_Connection' with your second snippet?
@GeorgeEdwards Try Integrated Security=SSPI; instead of Trusted_Connection=True;. Or Trusted_Connection=yes;
Hmm, now I just get Unhandled rejection SequelizeConnectionError: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]
Can you connect to localhost\MSSQLSERVER01 using SSMS and Windows Authentication? You should verify that, looks like it does not allow you to connect. Check this.
@GeorgeEdwards But this is another problem which is not really connected with your original question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.