1

I'm running a pretty simple node js app that tracks user hits on a given website. The development version is working just fine writing to a SQL 2012 Enterprise Server, but the production version is getting the following error:

error running query { RequestError: The INSERT permission was denied on the object 'StudentMonitor', database 'LearnOnlineStatus', schema 'dbo'.
    at StreamEvents.<anonymous> (C:\Node\MoodleMonitor\node_modules\mssql\lib\msnodesqlv8.js:624:21)
    at StreamEvents.g (events.js:286:16)
    at emitOne (events.js:96:13)
    at StreamEvents.emit (events.js:188:7)
    at routeStatementError (C:\Node\MoodleMonitor\node_modules\msnodesqlv8\lib\driverMgr.js:119:20)
    at onInvoke (C:\Node\MoodleMonitor\node_modules\msnodesqlv8\lib\driverMgr.js:476:17)
    at onQuery (C:\Node\MoodleMonitor\node_modules\msnodesqlv8\lib\driverMgr.js:157:17) name: 'RequestError',   message: 'The INSERT permission was denied on the object \'StudentMonitor\', database \'LearnOnlineStatus\', schema \' dbo\'.',   code: 'EREQUEST',   number: 229,   lineNumber: undefined,   state: '42000',   class: undefined,   serverName: undefined,   procName: undefined }

It's attempting to execute the following INSERT code:

mssql.getConnection(function(err, client, done) {
    for (var i = 0; i < 7; i++) {
      client.input('' + (i+1), data[i]);
    }

    client.query('INSERT INTO [dbo].[StudentMonitor] (time_created, user_id, ip, url, duration, page_title, course_id) VALUES (@1, @2, @3, @4, @5, @6, @7)', function(err, result) {
      if(err) {
        console.error('error running query', err);
      }
      // return the client to the connection pool for other requests to reuse
      done();

      return typeof callback === 'function' ? callback(err, result) : result;
    });
  });

All credentials listed in configurations are correct, and we've eliminated network issues as a symptom. Trying the insert statement via SQL Manager works fine with those credentials.

What drives me batty is that a select works just fine, and the user account we're using is DBOwner, so should have no issues whatsoever. Checking the table in SQL reveals no weird permissions or triggers, it's just a regular old table.

Currently running on two Windows 2012 (64-bit) R2 servers but the behaviour is the same on both. SQL Native Client 11.0 is installed, and I've added and removed ODBC clients with no impact. Credentials are set via a mssql.conf file that is all correct and confirmed from console logs. Any ideas?

ScottGage
  • 53
  • 1
  • 8

1 Answers1

0

Okay, was using trustedConnection:true with the mssql (lib/mssql.js) stuff, so it was using my credentials rather than the provided ones. Switching this out for false and adding user and password has resolved the issue.

ScottGage
  • 53
  • 1
  • 8