Connecting Tech Pros Worldwide Help | Site Map

Why doesn't this code work???

mheden@bigfoot.com
Guest
 
Posts: n/a
#1: Nov 13 '05
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=ImportCM;Database=ImportCM; UID=xxxx;
PWD=yyyy"
Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
Set conImportCM = wrkODBC.OpenConnection("", dbDriverNoPrompt, ,
strConnection)
Set qdf = conImportCM.CreateQueryDef("", "{ ? = call
prcCountViewContract}")

qdf.Parameters(0).Direction = dbParamReturnValue
qdf.Execute

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

The stored procedure that's being executed is:-

CREATE PROCEDURE prcCountViewContract
@Rows int = NULL OUTPUT
AS
SELECT ContractID FROM dbo.tblViewContract
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 prcCountViewContract' 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
Guest
 
Posts: n/a
#2: Nov 13 '05

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.googlegr oups.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=ImportCM;Database=ImportCM; UID=xxxx;
> PWD=yyyy"
> Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
> Set conImportCM = wrkODBC.OpenConnection("", dbDriverNoPrompt, ,
> strConnection)
> Set qdf = conImportCM.CreateQueryDef("", "{ ? = call
> prcCountViewContract}")
>
> qdf.Parameters(0).Direction = dbParamReturnValue
> qdf.Execute
>
> MsgBox "Row count is " & qdf.Parameters(0).Value
>
> The stored procedure that's being executed is:-
>
> CREATE PROCEDURE prcCountViewContract
> @Rows int = NULL OUTPUT
> AS
> SELECT ContractID FROM dbo.tblViewContract
> 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 prcCountViewContract' 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]


MikeH
Guest
 
Posts: n/a
#3: Nov 13 '05

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.googlegr oups.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=ImportCM;Database=ImportCM;[/color][/color]
UID=xxxx;[color=blue][color=green]
> > PWD=yyyy"
> > Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
> > Set conImportCM = wrkODBC.OpenConnection("", dbDriverNoPrompt,[/color][/color]
,[color=blue][color=green]
> > strConnection)
> > Set qdf = conImportCM.CreateQueryDef("", "{ ? = call
> > prcCountViewContract}")
> >
> > qdf.Parameters(0).Direction = dbParamReturnValue
> > qdf.Execute
> >
> > MsgBox "Row count is " & qdf.Parameters(0).Value
> >
> > The stored procedure that's being executed is:-
> >
> > CREATE PROCEDURE prcCountViewContract
> > @Rows int = NULL OUTPUT
> > AS
> > SELECT ContractID FROM dbo.tblViewContract
> > 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 prcCountViewContract' 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]

Terry Kreft
Guest
 
Posts: n/a
#4: Nov 13 '05

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).

http://support.microsoft.com/search/...&srchExtraQry=


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.googlegr oups.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.googlegr oups.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=ImportCM;Database=ImportCM;[/color][/color]
> UID=xxxx;[color=green][color=darkred]
> > > PWD=yyyy"
> > > Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
> > > Set conImportCM = wrkODBC.OpenConnection("", dbDriverNoPrompt,[/color][/color]
> ,[color=green][color=darkred]
> > > strConnection)
> > > Set qdf = conImportCM.CreateQueryDef("", "{ ? = call
> > > prcCountViewContract}")
> > >
> > > qdf.Parameters(0).Direction = dbParamReturnValue
> > > qdf.Execute
> > >
> > > MsgBox "Row count is " & qdf.Parameters(0).Value
> > >
> > > The stored procedure that's being executed is:-
> > >
> > > CREATE PROCEDURE prcCountViewContract
> > > @Rows int = NULL OUTPUT
> > > AS
> > > SELECT ContractID FROM dbo.tblViewContract
> > > 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 prcCountViewContract' 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]


MikeH
Guest
 
Posts: n/a
#5: Nov 13 '05

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

Terry Kreft
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Why doesn't this code work???


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

CREATE PROCEDURE prcCountViewContract
@Rows int = NULL OUTPUT
AS
SELECT @Rows = COUNT(*) FROM dbo.tblViewContract



--
Terry Kreft
MVP Microsoft Access


"MikeH" <mheden@bigfoot.com> wrote in message
news:1114512309.236860.179490@z14g2000cwz.googlegr oups.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]


MikeH
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Why doesn't this code work???


Terry,

I changed the stored procedure to:-

CREATE PROCEDURE prcCountViewContract
@Rows int = NULL OUTPUT
AS
SELECT @Rows = COUNT (*) FROM dbo.tblViewContract
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 prcCountViewContract
> @Rows int = NULL OUTPUT
> AS
> SELECT @Rows = COUNT(*) FROM dbo.tblViewContract
>
>
>
> --
> Terry Kreft
> MVP Microsoft Access
>
>
> "MikeH" <mheden@bigfoot.com> wrote in message
> news:1114512309.236860.179490@z14g2000cwz.googlegr oups.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]

Terry Kreft
Guest
 
Posts: n/a
#8: Nov 13 '05

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=ImportCM;Database=ImportCM;
UID=xxxx;PWD=yyyy"
Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
Set conImportCM = wrkODBC.OpenConnection("", dbDriverComplete, ,
strConnection)

' ***************************
' NOTE DIFFERENCE HERE
Set qdf = conImportCM.CreateQueryDef("", "{? = call
prcCountViewContract(?)}")

qdf.Parameters(0).Direction = dbParamReturnValue
qdf.Parameters(1).Direction = dbParamReturnValue
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.googlegr oups.com...[color=blue]
> Terry,
>
> I changed the stored procedure to:-
>
> CREATE PROCEDURE prcCountViewContract
> @Rows int = NULL OUTPUT
> AS
> SELECT @Rows = COUNT (*) FROM dbo.tblViewContract
> 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 prcCountViewContract
> > @Rows int = NULL OUTPUT
> > AS
> > SELECT @Rows = COUNT(*) FROM dbo.tblViewContract
> >
> >
> >
> > --
> > Terry Kreft
> > MVP Microsoft Access
> >
> >
> > "MikeH" <mheden@bigfoot.com> wrote in message
> > news:1114512309.236860.179490@z14g2000cwz.googlegr oups.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]


MikeH
Guest
 
Posts: n/a
#9: Nov 13 '05

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=ImportCM;Database=ImportCM;
> UID=xxxx;PWD=yyyy"
> Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
> Set conImportCM = wrkODBC.OpenConnection("", dbDriverComplete, ,
> strConnection)
>
> ' ***************************
> ' NOTE DIFFERENCE HERE
> Set qdf = conImportCM.CreateQueryDef("", "{? = call
> prcCountViewContract(?)}")
>
> qdf.Parameters(0).Direction = dbParamReturnValue
> qdf.Parameters(1).Direction = dbParamReturnValue
> 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.googlegr oups.com...[color=green]
> > Terry,
> >
> > I changed the stored procedure to:-
> >
> > CREATE PROCEDURE prcCountViewContract
> > @Rows int = NULL OUTPUT
> > AS
> > SELECT @Rows = COUNT (*) FROM dbo.tblViewContract
> > 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 prcCountViewContract
> > > @Rows int = NULL OUTPUT
> > > AS
> > > SELECT @Rows = COUNT(*) FROM dbo.tblViewContract
> > >
> > >
> > >
> > > --
> > > Terry Kreft
> > > MVP Microsoft Access
> > >
> > >
> > > "MikeH" <mheden@bigfoot.com> wrote in message
> > > news:1114512309.236860.179490@z14g2000cwz.googlegr oups.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]

Closed Thread