Calling All DAO / ODBC / SQL Experts - Need Help w. Stored Procedure Calls 
Author Message
 Calling All DAO / ODBC / SQL Experts - Need Help w. Stored Procedure Calls

Need help with ODBC Direct Calls to MS SQLServer 6.5 from ACCESS VBA

I'm trying to execute a stored procedure that has no input parameters and
one output
parameter (procedure is at bottom of this note).  I have not been successful
in both calling
the SP and retrieving the value of the output parameter from Access 97 using
ODBCDirect (or any other method). I can call a stored procedure that has no
input ot output
parameters (see CASE 2 below) with no problems.

HOW CAN I CALL A PROCEDURE WITH JUST AN OUTPUT PARAMETER AND GET THE
VALUE???

Below is what I have tried so far....

'Create An ODBCDirect Workspace:'

    strConnection = "ODBC;DSN=FCCU;"
    Set wsDirect = CreateWorkspace("ODBCDirect", "", "", dbUseODBC)
    Set dbFCCU = wsDirect.OpenDatabase("", False, False, strConnection)
    Set cnDirect = wsDirect.Connections(0)

'Set Up a Test SQL call (I only use one at a time, comment out the others):'

    strTestString = "EXECUTE RequestToolSetBalanceDataLoad ?"   TEST CASE
  -  Works, can't get return param
    strTestString = "{call CAMMSteadyStates }"
TEST CASE 2     -   Works, no parameters required
    strTestString = "{call RequestToolSetBalanceDataLoad (?) }"        TEST
CASE 3.1  -   Doesn't work
    strTestString = "{call RequestToolSetBalanceDataLoad ? }"          TEST
CASE 3.2
    strTestString = "{? = call RequestToolSetBalanceDataLoad }"       TEST
CASE 3.3

'Create and execute the QueryDef:'

    Set qdfDirect = cnDirect.CreateQueryDef("")

    qdfDirect.SQL = strTestString
    qdfDirect.Parameters(0).Direction = dbParamInputOutput
    qdfDirect.ODBCTimeout = 0
    qdfDirect.Execute
    intReturnedParam = qdfDirect.Parameters(0)
    qdfDirect.Close

TEST CASE 1 Works (code doesn't fail) but intReturnedParam is null  (when it
should have a value)

TEST CASE 2 Is a stored proc that has no input or output parameters.  This
case works as expected
            (but I have to comment out the parameter statements, since no
parameters are passed)

TEST CASE 3 This is the way I would expect it to work. But it always fails
on execution with an
ODBC error!  Checking the ODBC trace, the actual error is:

DIAG [37000] [Microsoft] [ODBC SQL Server Driver] [SQL SERVER] Procedure

supplied. (201)

For all cases above. I also tried setting Param Direction = dbParamOutput
and
dbParamReturnValue with same result. It is like the parameter is ignored for
Case 3

Stored Procedure for CASE 3 ( I cannot modify this - it is used by other
applications):

if exists (select * from sysobjects where id =
object_id('dbo.RequestToolSetBalanceDataLoad') and sysstat & 0xf = 4)
 drop procedure dbo.RequestToolSetBalanceDataLoad
GO

create procedure RequestToolSetBalanceDataLoad

)

as

 /**********************************************************************/
 /*    Service routine for the FCCU app.                               */
 /*    Reserves a handle for rows in the ToolSetBalanceDataLoad        */
 /*    table.                                                          */
 /*                                                                    */
 /*    Inputs : None                                                   */
 /*                                                                    */

 /*             used by the caller as the identifier it can use        */
 /*             when inserting rows in this table to know which        */
 /*             rows belong to it.                                     */
 /*                                                                    */
 /*    Returns: nothing                                                */
 /*                                                                    */
 /*    Selects: nothing                                                */
 /*                                                                    */
 /**********************************************************************/


ToolSetBalanceDataLoad

 insert into     ToolSetBalanceDataLoad
               ( Handle
               , Stream
               , CutPoint
               , Attribute
               , EngUnit
               , DataValue
               , FCCUAttribute
               )

               , replicate("*",30)
               , replicate("*",30)
               , replicate("*",30)
               , replicate("*",30)
               , 0.0
               , NULL
               )
GO

Thanks, Marty

--
Martin Lycan
Oakland, CA



Sun, 12 Jan 2003 03:00:00 GMT  
 Calling All DAO / ODBC / SQL Experts - Need Help w. Stored Procedure Calls

Marty, for a few worked examples check out

ACC: How to Return Values from SQL Stored Procedures
Article ID: Q128408

In short:
In SQL

CREATE PROCEDURE TEST
   AS






and in Access

   Function SP_Value ()
   Dim mydb As Database
   Dim myq As QueryDef
   Dim myrs As Recordset

   Set mydb = CurrentDB()
   Set myq = mydb.CreateQueryDef("")

   myq.connect = "ODBC;"
   myq.sql = "TEST"
   Set myrs = myq.OpenRecordset()
   MsgBox myrs!x
   MsgBox myrs!y

   End Function

Quote:

>Need help with ODBC Direct Calls to MS SQLServer 6.5 from ACCESS VBA

>I'm trying to execute a stored procedure that has no input parameters and
>one output
>parameter (procedure is at bottom of this note).  I have not been
successful
>in both calling
>the SP and retrieving the value of the output parameter from Access 97
using
>ODBCDirect (or any other method). I can call a stored procedure that has no
>input ot output
>parameters (see CASE 2 below) with no problems.

>HOW CAN I CALL A PROCEDURE WITH JUST AN OUTPUT PARAMETER AND GET THE
>VALUE???

>Below is what I have tried so far....

>'Create An ODBCDirect Workspace:'

>    strConnection = "ODBC;DSN=FCCU;"
>    Set wsDirect = CreateWorkspace("ODBCDirect", "", "", dbUseODBC)
>    Set dbFCCU = wsDirect.OpenDatabase("", False, False, strConnection)
>    Set cnDirect = wsDirect.Connections(0)

>'Set Up a Test SQL call (I only use one at a time, comment out the
others):'

>    strTestString = "EXECUTE RequestToolSetBalanceDataLoad ?"   TEST CASE
>  -  Works, can't get return param
>    strTestString = "{call CAMMSteadyStates }"
>TEST CASE 2     -   Works, no parameters required
>    strTestString = "{call RequestToolSetBalanceDataLoad (?) }"        TEST
>CASE 3.1  -   Doesn't work
>    strTestString = "{call RequestToolSetBalanceDataLoad ? }"          TEST
>CASE 3.2
>    strTestString = "{? = call RequestToolSetBalanceDataLoad }"       TEST
>CASE 3.3

>'Create and execute the QueryDef:'

>    Set qdfDirect = cnDirect.CreateQueryDef("")

>    qdfDirect.SQL = strTestString
>    qdfDirect.Parameters(0).Direction = dbParamInputOutput
>    qdfDirect.ODBCTimeout = 0
>    qdfDirect.Execute
>    intReturnedParam = qdfDirect.Parameters(0)
>    qdfDirect.Close

>TEST CASE 1 Works (code doesn't fail) but intReturnedParam is null  (when
it
>should have a value)

>TEST CASE 2 Is a stored proc that has no input or output parameters.  This
>case works as expected
>            (but I have to comment out the parameter statements, since no
>parameters are passed)

>TEST CASE 3 This is the way I would expect it to work. But it always fails
>on execution with an
>ODBC error!  Checking the ODBC trace, the actual error is:

>DIAG [37000] [Microsoft] [ODBC SQL Server Driver] [SQL SERVER] Procedure

>supplied. (201)

>For all cases above. I also tried setting Param Direction = dbParamOutput
>and
>dbParamReturnValue with same result. It is like the parameter is ignored
for
>Case 3

>Stored Procedure for CASE 3 ( I cannot modify this - it is used by other
>applications):

>if exists (select * from sysobjects where id =
>object_id('dbo.RequestToolSetBalanceDataLoad') and sysstat & 0xf = 4)
> drop procedure dbo.RequestToolSetBalanceDataLoad
>GO

>create procedure RequestToolSetBalanceDataLoad


>)

>as

> /**********************************************************************/
> /*    Service routine for the FCCU app.                               */
> /*    Reserves a handle for rows in the ToolSetBalanceDataLoad        */
> /*    table.                                                          */
> /*                                                                    */
> /*    Inputs : None                                                   */
> /*                                                                    */

> /*             used by the caller as the identifier it can use        */
> /*             when inserting rows in this table to know which        */
> /*             rows belong to it.                                     */
> /*                                                                    */
> /*    Returns: nothing                                                */
> /*                                                                    */
> /*    Selects: nothing                                                */
> /*                                                                    */
> /**********************************************************************/


>ToolSetBalanceDataLoad

> insert into     ToolSetBalanceDataLoad
>               ( Handle
>               , Stream
>               , CutPoint
>               , Attribute
>               , EngUnit
>               , DataValue
>               , FCCUAttribute
>               )

>               , replicate("*",30)
>               , replicate("*",30)
>               , replicate("*",30)
>               , replicate("*",30)
>               , 0.0
>               , NULL
>               )
>GO

>Thanks, Marty

>--
>Martin Lycan
>Oakland, CA




Mon, 13 Jan 2003 03:00:00 GMT  
 Calling All DAO / ODBC / SQL Experts - Need Help w. Stored Procedure Calls
Thanks John - I had seen this article, but in my case I don't have any control over how the stored
procedures are set up.
They are defined with input & output parameters, and from what I have read, the only way to pull a
parameter when making calls
via ODBCDirect is with parameter properties and and the {call sp (?)} ODBC syntax - unfortunately I
can't get it to work.

Marty

Quote:

> Marty, for a few worked examples check out

> ACC: How to Return Values from SQL Stored Procedures
> Article ID: Q128408

> In short:
> In SQL

> CREATE PROCEDURE TEST
>    AS






> and in Access

>    Function SP_Value ()
>    Dim mydb As Database
>    Dim myq As QueryDef
>    Dim myrs As Recordset

>    Set mydb = CurrentDB()
>    Set myq = mydb.CreateQueryDef("")

>    myq.connect = "ODBC;"
>    myq.sql = "TEST"
>    Set myrs = myq.OpenRecordset()
>    MsgBox myrs!x
>    MsgBox myrs!y

>    End Function


> >Need help with ODBC Direct Calls to MS SQLServer 6.5 from ACCESS VBA

> >I'm trying to execute a stored procedure that has no input parameters and
> >one output
> >parameter (procedure is at bottom of this note).  I have not been
> successful
> >in both calling
> >the SP and retrieving the value of the output parameter from Access 97
> using
> >ODBCDirect (or any other method). I can call a stored procedure that has no
> >input ot output
> >parameters (see CASE 2 below) with no problems.

> >HOW CAN I CALL A PROCEDURE WITH JUST AN OUTPUT PARAMETER AND GET THE
> >VALUE???

> >Below is what I have tried so far....

> >'Create An ODBCDirect Workspace:'

> >    strConnection = "ODBC;DSN=FCCU;"
> >    Set wsDirect = CreateWorkspace("ODBCDirect", "", "", dbUseODBC)
> >    Set dbFCCU = wsDirect.OpenDatabase("", False, False, strConnection)
> >    Set cnDirect = wsDirect.Connections(0)

> >'Set Up a Test SQL call (I only use one at a time, comment out the
> others):'

> >    strTestString = "EXECUTE RequestToolSetBalanceDataLoad ?"   TEST CASE
> >  -  Works, can't get return param
> >    strTestString = "{call CAMMSteadyStates }"
> >TEST CASE 2     -   Works, no parameters required
> >    strTestString = "{call RequestToolSetBalanceDataLoad (?) }"        TEST
> >CASE 3.1  -   Doesn't work
> >    strTestString = "{call RequestToolSetBalanceDataLoad ? }"          TEST
> >CASE 3.2
> >    strTestString = "{? = call RequestToolSetBalanceDataLoad }"       TEST
> >CASE 3.3

> >'Create and execute the QueryDef:'

> >    Set qdfDirect = cnDirect.CreateQueryDef("")

> >    qdfDirect.SQL = strTestString
> >    qdfDirect.Parameters(0).Direction = dbParamInputOutput
> >    qdfDirect.ODBCTimeout = 0
> >    qdfDirect.Execute
> >    intReturnedParam = qdfDirect.Parameters(0)
> >    qdfDirect.Close

> >TEST CASE 1 Works (code doesn't fail) but intReturnedParam is null  (when
> it
> >should have a value)

> >TEST CASE 2 Is a stored proc that has no input or output parameters.  This
> >case works as expected
> >            (but I have to comment out the parameter statements, since no
> >parameters are passed)

> >TEST CASE 3 This is the way I would expect it to work. But it always fails
> >on execution with an
> >ODBC error!  Checking the ODBC trace, the actual error is:

> >DIAG [37000] [Microsoft] [ODBC SQL Server Driver] [SQL SERVER] Procedure

> >supplied. (201)

> >For all cases above. I also tried setting Param Direction = dbParamOutput
> >and
> >dbParamReturnValue with same result. It is like the parameter is ignored
> for
> >Case 3

> >Stored Procedure for CASE 3 ( I cannot modify this - it is used by other
> >applications):

> >if exists (select * from sysobjects where id =
> >object_id('dbo.RequestToolSetBalanceDataLoad') and sysstat & 0xf = 4)
> > drop procedure dbo.RequestToolSetBalanceDataLoad
> >GO

> >create procedure RequestToolSetBalanceDataLoad


> >)

> >as

> > /**********************************************************************/
> > /*    Service routine for the FCCU app.                               */
> > /*    Reserves a handle for rows in the ToolSetBalanceDataLoad        */
> > /*    table.                                                          */
> > /*                                                                    */
> > /*    Inputs : None                                                   */
> > /*                                                                    */

> > /*             used by the caller as the identifier it can use        */
> > /*             when inserting rows in this table to know which        */
> > /*             rows belong to it.                                     */
> > /*                                                                    */
> > /*    Returns: nothing                                                */
> > /*                                                                    */
> > /*    Selects: nothing                                                */
> > /*                                                                    */
> > /**********************************************************************/


> >ToolSetBalanceDataLoad

> > insert into     ToolSetBalanceDataLoad
> >               ( Handle
> >               , Stream
> >               , CutPoint
> >               , Attribute
> >               , EngUnit
> >               , DataValue
> >               , FCCUAttribute
> >               )

> >               , replicate("*",30)
> >               , replicate("*",30)
> >               , replicate("*",30)
> >               , replicate("*",30)
> >               , 0.0
> >               , NULL
> >               )
> >GO

> >Thanks, Marty

> >--
> >Martin Lycan
> >Oakland, CA




Mon, 13 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP: Calling Stored Procedure w/large output from VB6 (using SQL Server)

2. HELP: Calling Stored Procedure w/large output from VB6 (using SQL Server)

3. HELP - ASP Calling SQL Server Stored procedure

4. HELP: Calling Stored Procedure w/large output from VB6 (using SQL Server)

5. Calling Oracle Stored Procedure from VB6 using DAO

6. Can DAO call stored procedures ?

7. How to call store procedure in Dao?

8. VB5 program calls Oracle stored procedure via ODBC

9. ODBC API error when calling Oracle stored procedure

10. Calling Oracle7 Stored Procedures via the ODBC 2.10 API

11. Calling an Oracle Stored Procedure through ODBC

12. Calling a SQL Server 2000 store procedure from MS-Access

 

 
Powered by phpBB® Forum Software