开发者

getting the result of stored procedure using JavaScript

I have a javaScript script that is not web related and need to run a stored procedure that contains a raise error statement, and make sure that the procedure was successfully run.

If I just do,

开发者_StackOverflow中文版
function runSQL()
{
    var rs = new ActiveXObject("ADODB.Recordset");

    try {
        rs.open("EXEX spAddToPar 'foo',1 , 2 ", conn);          
    }
    catch (e) {
        rs.close(); 
    }   
    rs.close();
}

How do I know if it ran successfully or not?


Currently you don't. You have just caught the only indication of any error and thrown it away.

In the catch block you would have to do something that you can later on check, for example changing the value of a variable:

function runSQL() {
  var rs = new ActiveXObject("ADODB.Recordset");
  var success = true;
  try {
    rs.open("EXEC spAddToPar 'foo', 1, 2", conn);          
  } catch (e) {
    success = false;
  }
  rs.close();
  return success;
}

Note: This only indicates if there was some sort of error or not. You might want to get more information out of the exception object if you want to know exactly what the error was. It's not certain that the exception comes from the stored procedure raising an error, there are other things that can go wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜