Why doesn't this code work???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mheden@bigfoot.com

    #1

    Why doesn't this code work???

    Hello all,

    I'm using an Access 97 front-end with a SQL Server 2000 back-end. One
    particular bit of code runs a stored procedure to obtain a rowcount
    from one of the back-end tables. This works fine on one PC, but not on
    another. For the life of me, I can't see why it fails to work in the
    'faulty' environment.

    This is the code:-

    Dim conImportCM As Connection
    Dim wrkODBC As Workspace
    Dim strConnection As String
    Dim qdf As QueryDef

    strConnection = "ODBC;DSN=Impor tCM;Database=Im portCM; UID=xxxx;
    PWD=yyyy"
    Set wrkODBC = CreateWorkspace ("", "", "", dbUseODBC)
    Set conImportCM = wrkODBC.OpenCon nection("", dbDriverNoPromp t, ,
    strConnection)
    Set qdf = conImportCM.Cre ateQueryDef("", "{ ? = call
    prcCountViewCon tract}")

    qdf.Parameters( 0).Direction = dbParamReturnVa lue
    qdf.Execute

    MsgBox "Row count is " & qdf.Parameters( 0).Value

    The stored procedure that's being executed is:-

    CREATE PROCEDURE prcCountViewCon tract
    @Rows int = NULL OUTPUT
    AS
    SELECT ContractID FROM dbo.tblViewCont ract
    RETURN @@ROWCOUNT
    GO

    This works fine on one PC running Windows 2000 and returns the expected
    rowcount in the message box. On a another PC running Windows 98 SE, it
    fails to return any data - the qdf.Parameters( 0).Value returns null.

    Initially, I thought it might be a permissions issue (because this is
    running under a different user account on the two machines), but I can
    fire-up MS Query on the Windows 98 machine and manually run the stored
    procedure with 'exec prcCountViewCon tract' OK, so it looks like the
    Windows 98 environment has the correct access to the SQL Server
    back-end.

    I've also updated MDAC on the Windows 98 machine so that it's the same
    version as that used on the Windows 2000 PC (2.7). That has made
    absolutely no difference to the symptoms.

    Any ideas?

    Thanks,

    Mike

  • Terry Kreft

    #2
    Re: Why doesn't this code work???


    Did you installl DCOM98 on the Win98 machine?

    This should have been done before you installed MDAC.

    --
    Terry Kreft
    MVP Microsoft Access


    <mheden@bigfoot .com> wrote in message
    news:1114421515 .766471.112130@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > Hello all,
    >
    > I'm using an Access 97 front-end with a SQL Server 2000 back-end. One
    > particular bit of code runs a stored procedure to obtain a rowcount
    > from one of the back-end tables. This works fine on one PC, but not on
    > another. For the life of me, I can't see why it fails to work in the
    > 'faulty' environment.
    >
    > This is the code:-
    >
    > Dim conImportCM As Connection
    > Dim wrkODBC As Workspace
    > Dim strConnection As String
    > Dim qdf As QueryDef
    >
    > strConnection = "ODBC;DSN=Impor tCM;Database=Im portCM; UID=xxxx;
    > PWD=yyyy"
    > Set wrkODBC = CreateWorkspace ("", "", "", dbUseODBC)
    > Set conImportCM = wrkODBC.OpenCon nection("", dbDriverNoPromp t, ,
    > strConnection)
    > Set qdf = conImportCM.Cre ateQueryDef("", "{ ? = call
    > prcCountViewCon tract}")
    >
    > qdf.Parameters( 0).Direction = dbParamReturnVa lue
    > qdf.Execute
    >
    > MsgBox "Row count is " & qdf.Parameters( 0).Value
    >
    > The stored procedure that's being executed is:-
    >
    > CREATE PROCEDURE prcCountViewCon tract
    > @Rows int = NULL OUTPUT
    > AS
    > SELECT ContractID FROM dbo.tblViewCont ract
    > RETURN @@ROWCOUNT
    > GO
    >
    > This works fine on one PC running Windows 2000 and returns the expected
    > rowcount in the message box. On a another PC running Windows 98 SE, it
    > fails to return any data - the qdf.Parameters( 0).Value returns null.
    >
    > Initially, I thought it might be a permissions issue (because this is
    > running under a different user account on the two machines), but I can
    > fire-up MS Query on the Windows 98 machine and manually run the stored
    > procedure with 'exec prcCountViewCon tract' OK, so it looks like the
    > Windows 98 environment has the correct access to the SQL Server
    > back-end.
    >
    > I've also updated MDAC on the Windows 98 machine so that it's the same
    > version as that used on the Windows 2000 PC (2.7). That has made
    > absolutely no difference to the symptoms.
    >
    > Any ideas?
    >
    > Thanks,
    >
    > Mike
    >[/color]


    Comment

    • MikeH

      #3
      Re: Why doesn't this code work???

      Terry,

      No, I just installed MDAC 2.7 - I didn't see anything in the
      documentation about installing DCOM first, and the MDAC installation
      didn't complain at all. I've since checked the version of DCOM on the
      Win 98SE machine - it is 'DCOM Win98 Gold 4.71.0.1719'.

      Should I install DCOM98 1.3, or am I clutching at straws here?

      Regards,

      Mike



      Terry Kreft wrote:[color=blue]
      > Did you installl DCOM98 on the Win98 machine?
      >
      > This should have been done before you installed MDAC.
      >
      > --
      > Terry Kreft
      > MVP Microsoft Access
      >
      >
      > <mheden@bigfoot .com> wrote in message
      > news:1114421515 .766471.112130@ z14g2000cwz.goo glegroups.com.. .[color=green]
      > > Hello all,
      > >
      > > I'm using an Access 97 front-end with a SQL Server 2000 back-end.[/color][/color]
      One[color=blue][color=green]
      > > particular bit of code runs a stored procedure to obtain a rowcount
      > > from one of the back-end tables. This works fine on one PC, but[/color][/color]
      not on[color=blue][color=green]
      > > another. For the life of me, I can't see why it fails to work in[/color][/color]
      the[color=blue][color=green]
      > > 'faulty' environment.
      > >
      > > This is the code:-
      > >
      > > Dim conImportCM As Connection
      > > Dim wrkODBC As Workspace
      > > Dim strConnection As String
      > > Dim qdf As QueryDef
      > >
      > > strConnection = "ODBC;DSN=Impor tCM;Database=Im portCM;[/color][/color]
      UID=xxxx;[color=blue][color=green]
      > > PWD=yyyy"
      > > Set wrkODBC = CreateWorkspace ("", "", "", dbUseODBC)
      > > Set conImportCM = wrkODBC.OpenCon nection("", dbDriverNoPromp t,[/color][/color]
      ,[color=blue][color=green]
      > > strConnection)
      > > Set qdf = conImportCM.Cre ateQueryDef("", "{ ? = call
      > > prcCountViewCon tract}")
      > >
      > > qdf.Parameters( 0).Direction = dbParamReturnVa lue
      > > qdf.Execute
      > >
      > > MsgBox "Row count is " & qdf.Parameters( 0).Value
      > >
      > > The stored procedure that's being executed is:-
      > >
      > > CREATE PROCEDURE prcCountViewCon tract
      > > @Rows int = NULL OUTPUT
      > > AS
      > > SELECT ContractID FROM dbo.tblViewCont ract
      > > RETURN @@ROWCOUNT
      > > GO
      > >
      > > This works fine on one PC running Windows 2000 and returns the[/color][/color]
      expected[color=blue][color=green]
      > > rowcount in the message box. On a another PC running Windows 98[/color][/color]
      SE, it[color=blue][color=green]
      > > fails to return any data - the qdf.Parameters( 0).Value returns[/color][/color]
      null.[color=blue][color=green]
      > >
      > > Initially, I thought it might be a permissions issue (because this[/color][/color]
      is[color=blue][color=green]
      > > running under a different user account on the two machines), but I[/color][/color]
      can[color=blue][color=green]
      > > fire-up MS Query on the Windows 98 machine and manually run the[/color][/color]
      stored[color=blue][color=green]
      > > procedure with 'exec prcCountViewCon tract' OK, so it looks like the
      > > Windows 98 environment has the correct access to the SQL Server
      > > back-end.
      > >
      > > I've also updated MDAC on the Windows 98 machine so that it's the[/color][/color]
      same[color=blue][color=green]
      > > version as that used on the Windows 2000 PC (2.7). That has made
      > > absolutely no difference to the symptoms.
      > >
      > > Any ideas?
      > >
      > > Thanks,
      > >
      > > Mike
      > >[/color][/color]

      Comment

      • Terry Kreft

        #4
        Re: Why doesn't this code work???

        IIRC, Wni98se has DCOM pre-installed in which case you shouldn't need to
        install it again, support articles on DCOM are at (watch for wrapping).




        DCOM has to be installed on a machine for ADO to work, having to install
        DCOM as a separate step is only an issue with Win95 and Win98 machines.


        --
        Terry Kreft
        MVP Microsoft Access


        "MikeH" <mheden@bigfoot .com> wrote in message
        news:1114499818 .042970.154590@ o13g2000cwo.goo glegroups.com.. .[color=blue]
        > Terry,
        >
        > No, I just installed MDAC 2.7 - I didn't see anything in the
        > documentation about installing DCOM first, and the MDAC installation
        > didn't complain at all. I've since checked the version of DCOM on the
        > Win 98SE machine - it is 'DCOM Win98 Gold 4.71.0.1719'.
        >
        > Should I install DCOM98 1.3, or am I clutching at straws here?
        >
        > Regards,
        >
        > Mike
        >
        >
        >
        > Terry Kreft wrote:[color=green]
        > > Did you installl DCOM98 on the Win98 machine?
        > >
        > > This should have been done before you installed MDAC.
        > >
        > > --
        > > Terry Kreft
        > > MVP Microsoft Access
        > >
        > >
        > > <mheden@bigfoot .com> wrote in message
        > > news:1114421515 .766471.112130@ z14g2000cwz.goo glegroups.com.. .[color=darkred]
        > > > Hello all,
        > > >
        > > > I'm using an Access 97 front-end with a SQL Server 2000 back-end.[/color][/color]
        > One[color=green][color=darkred]
        > > > particular bit of code runs a stored procedure to obtain a rowcount
        > > > from one of the back-end tables. This works fine on one PC, but[/color][/color]
        > not on[color=green][color=darkred]
        > > > another. For the life of me, I can't see why it fails to work in[/color][/color]
        > the[color=green][color=darkred]
        > > > 'faulty' environment.
        > > >
        > > > This is the code:-
        > > >
        > > > Dim conImportCM As Connection
        > > > Dim wrkODBC As Workspace
        > > > Dim strConnection As String
        > > > Dim qdf As QueryDef
        > > >
        > > > strConnection = "ODBC;DSN=Impor tCM;Database=Im portCM;[/color][/color]
        > UID=xxxx;[color=green][color=darkred]
        > > > PWD=yyyy"
        > > > Set wrkODBC = CreateWorkspace ("", "", "", dbUseODBC)
        > > > Set conImportCM = wrkODBC.OpenCon nection("", dbDriverNoPromp t,[/color][/color]
        > ,[color=green][color=darkred]
        > > > strConnection)
        > > > Set qdf = conImportCM.Cre ateQueryDef("", "{ ? = call
        > > > prcCountViewCon tract}")
        > > >
        > > > qdf.Parameters( 0).Direction = dbParamReturnVa lue
        > > > qdf.Execute
        > > >
        > > > MsgBox "Row count is " & qdf.Parameters( 0).Value
        > > >
        > > > The stored procedure that's being executed is:-
        > > >
        > > > CREATE PROCEDURE prcCountViewCon tract
        > > > @Rows int = NULL OUTPUT
        > > > AS
        > > > SELECT ContractID FROM dbo.tblViewCont ract
        > > > RETURN @@ROWCOUNT
        > > > GO
        > > >
        > > > This works fine on one PC running Windows 2000 and returns the[/color][/color]
        > expected[color=green][color=darkred]
        > > > rowcount in the message box. On a another PC running Windows 98[/color][/color]
        > SE, it[color=green][color=darkred]
        > > > fails to return any data - the qdf.Parameters( 0).Value returns[/color][/color]
        > null.[color=green][color=darkred]
        > > >
        > > > Initially, I thought it might be a permissions issue (because this[/color][/color]
        > is[color=green][color=darkred]
        > > > running under a different user account on the two machines), but I[/color][/color]
        > can[color=green][color=darkred]
        > > > fire-up MS Query on the Windows 98 machine and manually run the[/color][/color]
        > stored[color=green][color=darkred]
        > > > procedure with 'exec prcCountViewCon tract' OK, so it looks like the
        > > > Windows 98 environment has the correct access to the SQL Server
        > > > back-end.
        > > >
        > > > I've also updated MDAC on the Windows 98 machine so that it's the[/color][/color]
        > same[color=green][color=darkred]
        > > > version as that used on the Windows 2000 PC (2.7). That has made
        > > > absolutely no difference to the symptoms.
        > > >
        > > > Any ideas?
        > > >
        > > > Thanks,
        > > >
        > > > Mike
        > > >[/color][/color]
        >[/color]


        Comment

        • MikeH

          #5
          Re: Why doesn't this code work???

          Definitely clutching at straws now...

          The version of DCOM98 on the Windows 98SE PC wasn't the 'latest and
          greatest' so I installed 1.3. It didn't make any difference at all.
          The qdf.Parameters( 0).Value still returns null instead of the expected
          row count. Identical code runs fine on my Windows 2000 PC.

          Any more ideas anyone? ...or is this one of those cases where the
          quickest solution is going to be a re-write to get the row count in a
          different way?

          Thanks,

          Mike

          Comment

          • Terry Kreft

            #6
            Re: Why doesn't this code work???

            Mike,
            Looking at your original post again, I would have written the SP as

            CREATE PROCEDURE prcCountViewCon tract
            @Rows int = NULL OUTPUT
            AS
            SELECT @Rows = COUNT(*) FROM dbo.tblViewCont ract



            --
            Terry Kreft
            MVP Microsoft Access


            "MikeH" <mheden@bigfoot .com> wrote in message
            news:1114512309 .236860.179490@ z14g2000cwz.goo glegroups.com.. .[color=blue]
            > Definitely clutching at straws now...
            >
            > The version of DCOM98 on the Windows 98SE PC wasn't the 'latest and
            > greatest' so I installed 1.3. It didn't make any difference at all.
            > The qdf.Parameters( 0).Value still returns null instead of the expected
            > row count. Identical code runs fine on my Windows 2000 PC.
            >
            > Any more ideas anyone? ...or is this one of those cases where the
            > quickest solution is going to be a re-write to get the row count in a
            > different way?
            >
            > Thanks,
            >
            > Mike
            >[/color]


            Comment

            • MikeH

              #7
              Re: Why doesn't this code work???

              Terry,

              I changed the stored procedure to:-

              CREATE PROCEDURE prcCountViewCon tract
              @Rows int = NULL OUTPUT
              AS
              SELECT @Rows = COUNT (*) FROM dbo.tblViewCont ract
              RETURN @Rows
              GO

              .... and it works fine now. Thanks very much for your help!

              Regards,

              Mike



              Terry Kreft wrote:[color=blue]
              > Mike,
              > Looking at your original post again, I would have written the SP as
              >
              > CREATE PROCEDURE prcCountViewCon tract
              > @Rows int = NULL OUTPUT
              > AS
              > SELECT @Rows = COUNT(*) FROM dbo.tblViewCont ract
              >
              >
              >
              > --
              > Terry Kreft
              > MVP Microsoft Access
              >
              >
              > "MikeH" <mheden@bigfoot .com> wrote in message
              > news:1114512309 .236860.179490@ z14g2000cwz.goo glegroups.com.. .[color=green]
              > > Definitely clutching at straws now...
              > >
              > > The version of DCOM98 on the Windows 98SE PC wasn't the 'latest and
              > > greatest' so I installed 1.3. It didn't make any difference at[/color][/color]
              all.[color=blue][color=green]
              > > The qdf.Parameters( 0).Value still returns null instead of the[/color][/color]
              expected[color=blue][color=green]
              > > row count. Identical code runs fine on my Windows 2000 PC.
              > >
              > > Any more ideas anyone? ...or is this one of those cases where[/color][/color]
              the[color=blue][color=green]
              > > quickest solution is going to be a re-write to get the row count in[/color][/color]
              a[color=blue][color=green]
              > > different way?
              > >
              > > Thanks,
              > >
              > > Mike
              > >[/color][/color]

              Comment

              • Terry Kreft

                #8
                Re: Why doesn't this code work???

                BTW, you do realise that the RETURN statement is meant to return a value
                indicating success or failure and that normally it returns 0 to indicate
                success?

                I think your VBA code should be

                Dim wrkODBC As Workspace
                Dim strConnection As String
                Dim qdf As QueryDef

                strConnection = "ODBC;DSN=Impor tCM;Database=Im portCM;
                UID=xxxx;PWD=yy yy"
                Set wrkODBC = CreateWorkspace ("", "", "", dbUseODBC)
                Set conImportCM = wrkODBC.OpenCon nection("", dbDriverComplet e, ,
                strConnection)

                ' *************** ************
                ' NOTE DIFFERENCE HERE
                Set qdf = conImportCM.Cre ateQueryDef("", "{? = call
                prcCountViewCon tract(?)}")

                qdf.Parameters( 0).Direction = dbParamReturnVa lue
                qdf.Parameters( 1).Direction = dbParamReturnVa lue
                qdf.Execute

                MsgBox "Success is " & (qdf.Parameters (0).Value > 0)
                MsgBox "Row count is " & qdf.Parameters( 1).Value



                --
                Terry Kreft
                MVP Microsoft Access


                "MikeH" <mheden@bigfoot .com> wrote in message
                news:1114526488 .672159.221090@ o13g2000cwo.goo glegroups.com.. .[color=blue]
                > Terry,
                >
                > I changed the stored procedure to:-
                >
                > CREATE PROCEDURE prcCountViewCon tract
                > @Rows int = NULL OUTPUT
                > AS
                > SELECT @Rows = COUNT (*) FROM dbo.tblViewCont ract
                > RETURN @Rows
                > GO
                >
                > ... and it works fine now. Thanks very much for your help!
                >
                > Regards,
                >
                > Mike
                >
                >
                >
                > Terry Kreft wrote:[color=green]
                > > Mike,
                > > Looking at your original post again, I would have written the SP as
                > >
                > > CREATE PROCEDURE prcCountViewCon tract
                > > @Rows int = NULL OUTPUT
                > > AS
                > > SELECT @Rows = COUNT(*) FROM dbo.tblViewCont ract
                > >
                > >
                > >
                > > --
                > > Terry Kreft
                > > MVP Microsoft Access
                > >
                > >
                > > "MikeH" <mheden@bigfoot .com> wrote in message
                > > news:1114512309 .236860.179490@ z14g2000cwz.goo glegroups.com.. .[color=darkred]
                > > > Definitely clutching at straws now...
                > > >
                > > > The version of DCOM98 on the Windows 98SE PC wasn't the 'latest and
                > > > greatest' so I installed 1.3. It didn't make any difference at[/color][/color]
                > all.[color=green][color=darkred]
                > > > The qdf.Parameters( 0).Value still returns null instead of the[/color][/color]
                > expected[color=green][color=darkred]
                > > > row count. Identical code runs fine on my Windows 2000 PC.
                > > >
                > > > Any more ideas anyone? ...or is this one of those cases where[/color][/color]
                > the[color=green][color=darkred]
                > > > quickest solution is going to be a re-write to get the row count in[/color][/color]
                > a[color=green][color=darkred]
                > > > different way?
                > > >
                > > > Thanks,
                > > >
                > > > Mike
                > > >[/color][/color]
                >[/color]


                Comment

                • MikeH

                  #9
                  Re: Why doesn't this code work???

                  Terry,

                  Thanks for the clarification. I guess it comes as no surprise to you
                  that I'm a bit new to the use of SPs from Access. I think that was a
                  bit of playing "guess the syntax" on my part! Time to get the manuals
                  out....

                  At least it all works now. Thanks again for all your help. Much
                  appreciated.

                  Regards,

                  Mike





                  Terry Kreft wrote:[color=blue]
                  > BTW, you do realise that the RETURN statement is meant to return a[/color]
                  value[color=blue]
                  > indicating success or failure and that normally it returns 0 to[/color]
                  indicate[color=blue]
                  > success?
                  >
                  > I think your VBA code should be
                  >
                  > Dim wrkODBC As Workspace
                  > Dim strConnection As String
                  > Dim qdf As QueryDef
                  >
                  > strConnection = "ODBC;DSN=Impor tCM;Database=Im portCM;
                  > UID=xxxx;PWD=yy yy"
                  > Set wrkODBC = CreateWorkspace ("", "", "", dbUseODBC)
                  > Set conImportCM = wrkODBC.OpenCon nection("", dbDriverComplet e, ,
                  > strConnection)
                  >
                  > ' *************** ************
                  > ' NOTE DIFFERENCE HERE
                  > Set qdf = conImportCM.Cre ateQueryDef("", "{? = call
                  > prcCountViewCon tract(?)}")
                  >
                  > qdf.Parameters( 0).Direction = dbParamReturnVa lue
                  > qdf.Parameters( 1).Direction = dbParamReturnVa lue
                  > qdf.Execute
                  >
                  > MsgBox "Success is " & (qdf.Parameters (0).Value > 0)
                  > MsgBox "Row count is " & qdf.Parameters( 1).Value
                  >
                  >
                  >
                  > --
                  > Terry Kreft
                  > MVP Microsoft Access
                  >
                  >
                  > "MikeH" <mheden@bigfoot .com> wrote in message
                  > news:1114526488 .672159.221090@ o13g2000cwo.goo glegroups.com.. .[color=green]
                  > > Terry,
                  > >
                  > > I changed the stored procedure to:-
                  > >
                  > > CREATE PROCEDURE prcCountViewCon tract
                  > > @Rows int = NULL OUTPUT
                  > > AS
                  > > SELECT @Rows = COUNT (*) FROM dbo.tblViewCont ract
                  > > RETURN @Rows
                  > > GO
                  > >
                  > > ... and it works fine now. Thanks very much for your help!
                  > >
                  > > Regards,
                  > >
                  > > Mike
                  > >
                  > >
                  > >
                  > > Terry Kreft wrote:[color=darkred]
                  > > > Mike,
                  > > > Looking at your original post again, I would have written the SP[/color][/color][/color]
                  as[color=blue][color=green][color=darkred]
                  > > >
                  > > > CREATE PROCEDURE prcCountViewCon tract
                  > > > @Rows int = NULL OUTPUT
                  > > > AS
                  > > > SELECT @Rows = COUNT(*) FROM dbo.tblViewCont ract
                  > > >
                  > > >
                  > > >
                  > > > --
                  > > > Terry Kreft
                  > > > MVP Microsoft Access
                  > > >
                  > > >
                  > > > "MikeH" <mheden@bigfoot .com> wrote in message
                  > > > news:1114512309 .236860.179490@ z14g2000cwz.goo glegroups.com.. .
                  > > > > Definitely clutching at straws now...
                  > > > >
                  > > > > The version of DCOM98 on the Windows 98SE PC wasn't the 'latest[/color][/color][/color]
                  and[color=blue][color=green][color=darkred]
                  > > > > greatest' so I installed 1.3. It didn't make any difference at[/color]
                  > > all.[color=darkred]
                  > > > > The qdf.Parameters( 0).Value still returns null instead of the[/color]
                  > > expected[color=darkred]
                  > > > > row count. Identical code runs fine on my Windows 2000 PC.
                  > > > >
                  > > > > Any more ideas anyone? ...or is this one of those cases[/color][/color][/color]
                  where[color=blue][color=green]
                  > > the[color=darkred]
                  > > > > quickest solution is going to be a re-write to get the row[/color][/color][/color]
                  count in[color=blue][color=green]
                  > > a[color=darkred]
                  > > > > different way?
                  > > > >
                  > > > > Thanks,
                  > > > >
                  > > > > Mike
                  > > > >[/color]
                  > >[/color][/color]

                  Comment

                  Working...