SQL Server 2000 stored procedure not returning rows 
Author Message
 SQL Server 2000 stored procedure not returning rows

Hi all,

I am trying to return results from a stored procedure in SQL Server 2000.
No problem there, I've done it bunches.  But for some reason this procedure
will not return the rows.  I get a "Operation not allowed when object is
closed" error.  Here is the sp I am trying to run:


as






create table #compare(
 compname nvarchar(15),
 compqtyA int,
 compqtyB int,
 pricediff smallmoney)

declare modelA cursor local for
 select
  g3.compname,
  g3.compqty,
  c.complist * g3.compqty
 from
  grp3 as g3
 inner join
  compnt as c
 on
  c.ctrt = g3.ctrt
  and c.compname = g3.compname
 where


 order by
  g3.compname

open modelA


 begin

  insert
   #compare(compname,
    compqtyA,
    pricediff)
  values(




 end

close modelA
deallocate modelA

declare modelB cursor scroll local for
 select
  g3.compname,
  g3.compqty,
  c.complist * g3.compqty
 from
  grp3 as g3
 inner join
  compnt as c
 on
  c.ctrt = g3.ctrt
  and c.compname = g3.compname
 where


 order by
  g3.compname

open modelB


 begin

  from
   #compare
  where


  begin
  insert
   #compare(compname,
    compqtyA,
    compqtyB,
    pricediff)
  values(

   0,


  end
 else
  begin

  update
   #compare
  set


  where

  end

 end

close modelB
deallocate modelB

update
 #compare
set
 compqtyB = -compqtyA
where
 compqtyB is null

select
 c.compname,
 c.compqtyA,
 c.compqtyB,
 c.pricediff
from
 #compare as c
where
 c.compqtyB <> 0
order by
 c.compname

This owrks fine if I call it from the query analyzer and I get the rows I
expect, but for some reason this doesn't return anything when I try to call
it from VB with this code:

    Dim conCompare As ADODB.Connection
    Dim cmdCompare As ADODB.Command
    Dim rsCompare As ADODB.Recordset
    Dim ContractID as String
    Dim ModelA as String
    Dim ModelB as String

    Set conCompare = New ADODB.Connection
    Set cmdCompare = New ADODB.Command
    Set rsCompare = New ADODB.Recordset

    conCompare.ConnectionString = ConnString
    conCompare.Open

    With cmdCompare
        .CommandType = adCmdStoredProc
        .CommandText = "sbs_pcscompare"
        Set .ActiveConnection = conCompare

adParamInput, 15, ContractID)

adParamInput, 50, ModelA)

adParamInput, 50, ModelB)

        Set rsCompare = .Execute

        arrResults = rsCompare.GetRows
    End With

    conCompare.Close

Any ideas?

Thanks in advance,
John Palmer



Tue, 23 Dec 2003 23:58:34 GMT  
 SQL Server 2000 stored procedure not returning rows
Try putting SET NOCOUNT ON at the top of your procedure definition.

--
Darren Brinksneader MCDBA, MCSE+I, CNE, CCA, MCT, CTT


Quote:
> Hi all,

> I am trying to return results from a stored procedure in SQL Server 2000.
> No problem there, I've done it bunches.  But for some reason this
procedure
> will not return the rows.  I get a "Operation not allowed when object is
> closed" error.  Here is the sp I am trying to run:

> create procedure sbs_pcscompare



> as






> create table #compare(
>  compname nvarchar(15),
>  compqtyA int,
>  compqtyB int,
>  pricediff smallmoney)

> declare modelA cursor local for
>  select
>   g3.compname,
>   g3.compqty,
>   c.complist * g3.compqty
>  from
>   grp3 as g3
>  inner join
>   compnt as c
>  on
>   c.ctrt = g3.ctrt
>   and c.compname = g3.compname
>  where


>  order by
>   g3.compname

> open modelA


>  begin

>   insert
>    #compare(compname,
>     compqtyA,
>     pricediff)
>   values(




>  end

> close modelA
> deallocate modelA

> declare modelB cursor scroll local for
>  select
>   g3.compname,
>   g3.compqty,
>   c.complist * g3.compqty
>  from
>   grp3 as g3
>  inner join
>   compnt as c
>  on
>   c.ctrt = g3.ctrt
>   and c.compname = g3.compname
>  where


>  order by
>   g3.compname

> open modelB


>  begin

>   from
>    #compare
>   where


>   begin
>   insert
>    #compare(compname,
>     compqtyA,
>     compqtyB,
>     pricediff)
>   values(

>    0,


>   end
>  else
>   begin

>   update
>    #compare
>   set


>   where

>   end

>  end

> close modelB
> deallocate modelB

> update
>  #compare
> set
>  compqtyB = -compqtyA
> where
>  compqtyB is null

> select
>  c.compname,
>  c.compqtyA,
>  c.compqtyB,
>  c.pricediff
> from
>  #compare as c
> where
>  c.compqtyB <> 0
> order by
>  c.compname

> This owrks fine if I call it from the query analyzer and I get the rows I
> expect, but for some reason this doesn't return anything when I try to
call
> it from VB with this code:

>     Dim conCompare As ADODB.Connection
>     Dim cmdCompare As ADODB.Command
>     Dim rsCompare As ADODB.Recordset
>     Dim ContractID as String
>     Dim ModelA as String
>     Dim ModelB as String

>     Set conCompare = New ADODB.Connection
>     Set cmdCompare = New ADODB.Command
>     Set rsCompare = New ADODB.Recordset

>     conCompare.ConnectionString = ConnString
>     conCompare.Open

>     With cmdCompare
>         .CommandType = adCmdStoredProc
>         .CommandText = "sbs_pcscompare"
>         Set .ActiveConnection = conCompare

> adParamInput, 15, ContractID)

> adParamInput, 50, ModelA)

> adParamInput, 50, ModelB)

>         Set rsCompare = .Execute

>         arrResults = rsCompare.GetRows
>     End With

>     conCompare.Close

> Any ideas?

> Thanks in advance,
> John Palmer



Wed, 24 Dec 2003 00:02:15 GMT  
 SQL Server 2000 stored procedure not returning rows
Thank you guys SO much.  Worked like a charm AND I am now imprving
performance on some of my other sp's.

Sincerely,
John Palmer


Quote:
> Hi all,

> I am trying to return results from a stored procedure in SQL Server 2000.
> No problem there, I've done it bunches.  But for some reason this
procedure
> will not return the rows.  I get a "Operation not allowed when object is
> closed" error.  Here is the sp I am trying to run:

> create procedure sbs_pcscompare



> as






> create table #compare(
>  compname nvarchar(15),
>  compqtyA int,
>  compqtyB int,
>  pricediff smallmoney)

> declare modelA cursor local for
>  select
>   g3.compname,
>   g3.compqty,
>   c.complist * g3.compqty
>  from
>   grp3 as g3
>  inner join
>   compnt as c
>  on
>   c.ctrt = g3.ctrt
>   and c.compname = g3.compname
>  where


>  order by
>   g3.compname

> open modelA


>  begin

>   insert
>    #compare(compname,
>     compqtyA,
>     pricediff)
>   values(




>  end

> close modelA
> deallocate modelA

> declare modelB cursor scroll local for
>  select
>   g3.compname,
>   g3.compqty,
>   c.complist * g3.compqty
>  from
>   grp3 as g3
>  inner join
>   compnt as c
>  on
>   c.ctrt = g3.ctrt
>   and c.compname = g3.compname
>  where


>  order by
>   g3.compname

> open modelB


>  begin

>   from
>    #compare
>   where


>   begin
>   insert
>    #compare(compname,
>     compqtyA,
>     compqtyB,
>     pricediff)
>   values(

>    0,


>   end
>  else
>   begin

>   update
>    #compare
>   set


>   where

>   end

>  end

> close modelB
> deallocate modelB

> update
>  #compare
> set
>  compqtyB = -compqtyA
> where
>  compqtyB is null

> select
>  c.compname,
>  c.compqtyA,
>  c.compqtyB,
>  c.pricediff
> from
>  #compare as c
> where
>  c.compqtyB <> 0
> order by
>  c.compname

> This owrks fine if I call it from the query analyzer and I get the rows I
> expect, but for some reason this doesn't return anything when I try to
call
> it from VB with this code:

>     Dim conCompare As ADODB.Connection
>     Dim cmdCompare As ADODB.Command
>     Dim rsCompare As ADODB.Recordset
>     Dim ContractID as String
>     Dim ModelA as String
>     Dim ModelB as String

>     Set conCompare = New ADODB.Connection
>     Set cmdCompare = New ADODB.Command
>     Set rsCompare = New ADODB.Recordset

>     conCompare.ConnectionString = ConnString
>     conCompare.Open

>     With cmdCompare
>         .CommandType = adCmdStoredProc
>         .CommandText = "sbs_pcscompare"
>         Set .ActiveConnection = conCompare

> adParamInput, 15, ContractID)

> adParamInput, 50, ModelA)

> adParamInput, 50, ModelB)

>         Set rsCompare = .Execute

>         arrResults = rsCompare.GetRows
>     End With

>     conCompare.Close

> Any ideas?

> Thanks in advance,
> John Palmer



Wed, 24 Dec 2003 00:37:41 GMT  
 SQL Server 2000 stored procedure not returning rows
John, see the programming FAQ on my site which talks about something similar
( http://vyaskn.tripod.com/programming_faq.htm#q10 )
--
HTH,
Vyas
Visit my site for Replication FAQ, Code samples, Database Interview
questions,
Database naming conventions, Database programming guidelines,
Interesting articles, Links and much more at:
http://vyaskn.tripod.com/


Hi all,

I am trying to return results from a stored procedure in SQL Server 2000.
No problem there, I've done it bunches.  But for some reason this procedure
will not return the rows.  I get a "Operation not allowed when object is
closed" error.  Here is the sp I am trying to run:


as






create table #compare(
 compname nvarchar(15),
 compqtyA int,
 compqtyB int,
 pricediff smallmoney)

declare modelA cursor local for
 select
  g3.compname,
  g3.compqty,
  c.complist * g3.compqty
 from
  grp3 as g3
 inner join
  compnt as c
 on
  c.ctrt = g3.ctrt
  and c.compname = g3.compname
 where


 order by
  g3.compname

open modelA


 begin

  insert
   #compare(compname,
    compqtyA,
    pricediff)
  values(




 end

close modelA
deallocate modelA

declare modelB cursor scroll local for
 select
  g3.compname,
  g3.compqty,
  c.complist * g3.compqty
 from
  grp3 as g3
 inner join
  compnt as c
 on
  c.ctrt = g3.ctrt
  and c.compname = g3.compname
 where


 order by
  g3.compname

open modelB


 begin

  from
   #compare
  where


  begin
  insert
   #compare(compname,
    compqtyA,
    compqtyB,
    pricediff)
  values(

   0,


  end
 else
  begin

  update
   #compare
  set


  where

  end

 end

close modelB
deallocate modelB

update
 #compare
set
 compqtyB = -compqtyA
where
 compqtyB is null

select
 c.compname,
 c.compqtyA,
 c.compqtyB,
 c.pricediff
from
 #compare as c
where
 c.compqtyB <> 0
order by
 c.compname

This owrks fine if I call it from the query analyzer and I get the rows I
expect, but for some reason this doesn't return anything when I try to call
it from VB with this code:

    Dim conCompare As ADODB.Connection
    Dim cmdCompare As ADODB.Command
    Dim rsCompare As ADODB.Recordset
    Dim ContractID as String
    Dim ModelA as String
    Dim ModelB as String

    Set conCompare = New ADODB.Connection
    Set cmdCompare = New ADODB.Command
    Set rsCompare = New ADODB.Recordset

    conCompare.ConnectionString = ConnString
    conCompare.Open

    With cmdCompare
        .CommandType = adCmdStoredProc
        .CommandText = "sbs_pcscompare"
        Set .ActiveConnection = conCompare

adParamInput, 15, ContractID)

adParamInput, 50, ModelA)

adParamInput, 50, ModelB)

        Set rsCompare = .Execute

        arrResults = rsCompare.GetRows
    End With

    conCompare.Close

Any ideas?

Thanks in advance,
John Palmer



Wed, 24 Dec 2003 00:30:53 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. SQL Server 2000 stored procedure not returning rows

2. HELP!!!!, using ADO + SQL 2000 + Stored procedures does not return a value

3. HELP!!!!, using ADO + SQL 2000 + Stored procedures does not return a value

4. Sql server stored procedures not returning a recordset...?

5. doing updating from grid to sql server with stored procedure sql 2000

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

7. VB.NET,SQL SERVER 2000 STORED PROCEDURE PARAMETERS, CRYSTAL REPORTS

8. Crystal Reports 8.5, SQL Server 2000, and Stored Procedures

9. Type Name is Invalid error -- Windows 2000/98 application with SQL Server/stored procedure problem

10. Logging SQL Server 2000 Stored Procedure Output

11. Help Retrieve Result From Store Procedure (SQL Server 2000)

12. Getting row from SQL Server stored procedure

 

 
Powered by phpBB® Forum Software