b3bel
b3bel

Reputation: 415

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,

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?

Upvotes: 1

Views: 2601

Answers (1)

Guffa
Guffa

Reputation: 700630

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.

Upvotes: 1

Related Questions