tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.22k stars 464 forks source link

Error with using uniqueidentifier in Node.JS. #1554

Closed Oolix closed 10 months ago

Oolix commented 10 months ago

I'm working with auth0 trying to implement my custom DB and I've run into a problem with making calls to a stored procedure. Whenever I try to make a query it throws the error: Error converting data type varchar to uniqueidentifier. According to the documentation I shouldn't have to do anything special but I have tried doing a CONVERT inside of my query and still no luck.

Expected behaviour:

const sql = require('mssql');
var guid = '00000000-0000-0000-0000-000000000000';
var query = "EXEC Auth.GetLoggedIn @EmailAddress, @ApplicationGUID, @FirstName OUTPUT, @LastName OUTPUT, @UserGUID OUTPUT, @UserPassword OUTPUT, @DisabledDateTime OUTPUT, @EmailAuthorization OUTPUT";

var connection = sql.connect( { 
    user: '', 
    password: ', 
    server: '', 
    database: '',
    options: {
      encrypt: true
    }
  }).then(function(pool) {
    return pool.request()
        .input("EmailAddress", sql.VarChar, email)
        .input("ApplicationGUID", sql.UniqueIdentifier, guid)
        .output("FirstName", sql.VarChar(50))
        .output("LastName", sql.VarChar(50))
        .output("UserGUID", sql.UniqueIdentifier)
        .output("UserPassword", sql.VarChar(1024))
        .output("DisabledDateTime", sql.DateTime)
        .output("EmailAuthorization", sql.DateTime)
      .query(query);
  }).then(function(result) {

  });

Actual behaviour:

Error converting data type varchar to uniqueidentifier.

Configuration:

LOG:

 Code generated an uncaught exception:  RequestError: Error converting data type varchar to uniqueidentifier.
    at /data/_verquire/_node18/mssql/3.3.0/node_modules/mssql/lib/tedious.js:739:17
    at Connection.emit (node:events:513:28)
    at Connection.emit (node:domain:552:15)
    at Parser.<anonymous> (/data/_verquire/_node18/mssql/3.3.0/node_modules/tedious/lib/connection.js:204:16)
    at Parser.emit (node:events:513:28)
    at Parser.emit (node:domain:552:15)
    at Parser.<anonymous> (/data/_verquire/_node18/mssql/3.3.0/node_modules/tedious/lib/token/token-stream-parser.js:42:15)
    at Parser.emit (node:events:513:28)
    at Parser.emit (node:domain:552:15)
    at addChunk (/data/_verquire/_node18/stackify-logger/1.0.9/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_readable.js:291:12)

Software versions

dhensby commented 10 months ago

What version of this library are you using (latest is not a version)

This isn't really a problem with the library, it's likely a problem with the database or values you have in the database.

Is the user guid column actually stored as a UniqueIdentifier? What if you use varchar instead of unique identifier? Is the error coming from the input data or the output (remove one or the other from the query to see if it makes a difference)?