Asked  10 Months ago    Answers:  5   Viewed   7 times

I've written a VBScript function to call a stored procedure. In the past, I've written a number of functions calling stored procedures with input parameters, but in this instance, I need to work with an Output parameter.

In another application, I call the exact same stored procedure using the Entity Framework, so the stored procedure is fine.

Here's my code:

Function checkAccess(userid,link)
    isAllowed = false

    set cmd = Server.CreateObject("ADODB.Command")
    cmd.CommandText = "Check_Permission"
    cmd.ActiveConnection = Conn
    cmd.NamedParameters = true
    cmd.CommandType = adCmdStoredProc
    cmd.Parameters.Append(cmd.CreateParameter("@Login", adVarChar, adParamInput, 50, userId))
    cmd.Parameters.Append(cmd.CreateParameter("@LinkId", adInteger, adParamInput, 50, link))    
    cmd.Parameters.Append(cmd.CreateParameter("@IsAllowed", adBoolean, adParamOutput, 10, isAllowed))

    checkAccess = isAllowed
End Function

This function always returns false. How do I make it work?

 Answers

2

You should return the value of your output parameter:

checkAccess = cmd.Parameters("@IsAllowed").Value

Also, output parameters in ADO don't require an initial value and adBoolean parameters don't require a size, so you could change your the last paramter to:

cmd.Parameters.Append(cmd.CreateParameter("@IsAllowed", adBoolean, adParamOutput))

You could also get rid of your isAllowed variable since it is no longer necessary.

Monday, August 16, 2021
 
TV Nath
 
3

Use the adodb.command object.

with createobject("adodb.command")
    .activeConnection = application("connectionstring")
    .commandText = "select * from sometable where id=?"
    set rs = .execute( ,array(123))
end with

I would also advise to use a custom db access object instead of using adodb directly. This allows you to build a nicer api, improves testability and add hooks for debuging/logging/profiling. Secondly you can add request scoped transactions with implicit rollback's on errors using the class_terminiate event. Oure db access object offers the following query api

call db.execute("update some_table set column=? where id=?", array(value, id))
set rs = db.fetch_rs("select * from some_table where id=?", array(id))
count = db.fetch_scalar("select count(*) from some_table where column > ?", array(value))
Friday, June 11, 2021
3

It should work like this:

DECLARE @dateval DATETIME

EXECUTE ('begin my1.spGetDate(?); end;', @dateval OUTPUT) AT ORA_DBLINK_NAME;

EXECUTE ('begin my1.spDeleteOldRecords(?); end;', @dateval) AT ORA_DBLINK_NAME;

If you have several parameters, it could look like this:

EXECUTE ('begin my1.spProc(?,?,?,?); end;', @param_in_1, @param_in_2, @param_out_3 OUTPUT, @param_out_4 OUTPUT) AT DBLINK_NAME;
Monday, August 2, 2021
 
5

We use something like the following in our code

public Map<String, Object> findData() {
        List prmtrsList = new ArrayList();
        prmtrsList.add(new SqlParameter(Types.VARCHAR));
        prmtrsList.add(new SqlParameter(Types.VARCHAR));
        prmtrsList.add(new SqlOutParameter("result", Types.VARCHAR));

        Map<String, Object> resultData = jdbcTemplate.call(connection -> {
            CallableStatement callableStatement = connection.prepareCall("{call STORED_PROC(?, ?, ?)}");
            callableStatement.setString(1, "first");
            callableStatement.setString(2, "last");
            callableStatement.registerOutParameter(3, Types.VARCHAR);
            return callableStatement;
        }, prmtrsList);
        return resultData;
    }
Friday, August 20, 2021
 
Xavio
 
5

You need a connection object.

set conn = server.CreateObject("adodb.connection")
set oRs = conn.execute(sSql)
Tuesday, October 5, 2021
 
netimen
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share