1

mssqlを使用してNodeJsでストアド プロシージャを実行しようとしているときに、ストアド プロシージャに「渡されたパラメータが多すぎます」というエラーが発生しました。

コード:

//This computerName is what we'll find in our mssql server to see
//if the server entry exist or not and the stored procedure will take this as a parameter.
var computerName = "some.fake.server.com";
var secProfile = "";

//Logic
// If computerName passed is valid and not null.
//if (computerName != "") {
var sql = require('mssql');

var config = {
    user: 'dbuser',
    password: 'secure9ass',
    server: 'dbserver.domain.com',
    database: 'DBName',
    pool: {
        max: 10,
        min: 0,
        idleTimeoutMillis: 30000
    }
}

sql.connect(config).then(function(output) {
  // Stored Procedure
    new sql.Request()
    .input("ComputerName", sql.VarChar(100), computerName)
  .output('sqlOutput', sql.VarChar(1000), "Stored procedure has not run yet!!")
    .execute('dbo.getSysStatus_ByName').then(function(recordsets) {
    console.dir(recordsets);
  }).catch(function(err) {
        // ... error checks
    console.log('ERROR1::: ' + err)
    console.log("----")
    console.log(err)
    console.log("====")
    console.log(recordsets)
    console.log("----")
    console.log('ERROR2::: '+ sqlOutput);
    console.log('ERROR3::: '+ request.parameters.sqlOutput.value);
});
  console.log(output);
}).catch(function(err) {
  // ... error checks
  console.log('ERROR5::: '+ err);
});

エラー: プロシージャー名に渡されたパラメーターが多すぎます: getSysStatus_ByName

データベースで、ストアド プロシージャに必要なパラメーターが 1 つしかなく、そのパラメーターが ComputerName であることを確認しました。

パラメータの名前だけが欠けていることはわかっていますが、試しました

.input("@ComputerName", sql.VarChar(100), computerName)

また

.input("computerName", sql.VarChar(100), computerName)

また

.input("computername", sql.VarChar(100), computerName)

何も機能せず、同じエラーが発生します。また、パラメーターの型を sql.VarChar(xxx) から sql.Int に変更しようとしました (この場合、無効な型と言ってエラーになるため、sql.VarChar(xxx) が適切であることがわかります。

正常に実行される .vb (Visual Basic) スクリプトの 1 つには、次のコード行があり、機能します。nodejs のコードでエラーが発生する理由を知りたいです。

                      Set objCmd = CreateObject("ADODB.Command")

                      ObjCmd.ActiveConnection = Conn

                      ObjCmd.CommandTimeout  = 180 'in seconds

                      ObjCmd.CommandType = 4          'Stored Procedure

                      ObjCmd.CommandText = "dbo.getSysStatus_ByName"

                      objCmd.Parameters.Append objCmd.CreateParameter("@ComputerName", 200, 1, 1024, ComputerName)

CreateParameter (ADO ヘルプページ) によると、200 は

adVarChar 200 A string value (Parameter object only). 

1 means: direction variable (where 1 is for an Input Parameter in my case) and
1024 is the size of the input variable.

試す VPN 接続はありませんが、サイズが 1024 対 1000 であるためにエラーが発生しないことを願っています (.input(..) 行のコード例で)。明日テストします。

4

1 に答える 1