Parentheses in Function with ODBC Connection String Cause Error When Used in Script

The information in this article applies to product: e-Work 6.x

Issue

  • An e-Work procedure contained a server-side VBScript with the following 2 functions - one that runs ExecSQL() against the e-Work database and one that runs ExecSQL() against an external database.

    Function insertEwork()
    ework.ExecSQL("INSERT INTO distributor\_counties (distrib\_id,county\_name,st\_key,zip\_code,discty\_notes) VALUES (1,'e-Work Script Cty','VA','22003','e-Work Script Test Notes')")
    End Function

    Function insertExternal()
    ework.ExecSQL("INSERT INTO distributor\_counties (distrib\_id,county\_name,st\_key,zip\_code,discty\_notes) VALUES (4,'IW Ext Cty','VA','22003','IW Ext Test Notes')","DSN=ework2;UID=ework;PWD=secret")
    End Function

    When either of these functions was called from 'When button pressed', the user received a 'Failed to refresh form' error and the following was written to the e-Work Designer log:

    Pre Eval: %Script(VBScript,,%Procedure.Name,%MapName,"insertEwork ")
    Post Eval: %Script(VBScript,,Database Insertions,External DB Scripts,insertEwork )
    Details: Unable to load script text, reason <0x80020101>. Procedure Script call failed. Position: 58

Resolution

  • Remove the parentheses from the ExecSQL() that contains a database connection string. The revised script is:

    Function insertEwork()
    ework.ExecSQL("INSERT INTO distributor\_counties (distrib\_id,county\_name,st\_key,zip\_code,discty\_notes) VALUES (1,'e-Work Script Cty','VA','22003','e-Work Script Test Notes')")
    End Function

    Function insertExternal()
    ework.ExecSQL"INSERT INTO distributor\_counties (distrib\_id,county\_name,st\_key,zip\_code,discty\_notes) VALUES (4,'IW Ext Cty','VA','22003','IW Ext Test Notes')","DSN=ework2;UID=ework;PWD=secret"
    End Function

Tagged: