[ADO] Stored Proc, resultset closed

Pagina: 1
Acties:

  • Nexopheus
  • Registratie: Juni 2001
  • Laatst online: 28-01 13:50
Ik heb een erg raar probleem nml:

Database : MSSQL
Stored procedure:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
REATE PROCEDURE sp_GeoInfo
@ipNrs VARCHAR(255)

AS
DECLARE @strIP VARCHAR(100)
DECLARE @strIPLEFT VARCHAR(100)

DECLARE @ipNO FLOAT

declare @countrySHORT nvarchar(2) 
declare @countryLONG nvarchar(64) 
declare @region nvarchar(128) 
declare @city nvarchar(128) 
declare @isp nvarchar(255) 


CREATE TABLE #tempResult (
    [ipNo] [float] NOT NULL PRIMARY KEY,
    [countrySHORT] [nvarchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [countryLONG] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [region] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [city] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [isp] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
)
while(PATINDEX('%;%', @ipNrs)<> 0)
begin
    SET @strIP = SUBSTRING(@ipNrs, 1, PATINDEX('%;%', @ipNrs) - 1)
    SET @strIPLEFT = SUBSTRING(@ipNrs, PATINDEX('%;%', @ipNrs) + 1, LEN(@ipNrs))
    SET @ipNrs = @strIPLEFT 
    SET @ipNO = @strIP
    
    SELECT TOP 1 @countrySHORT=countrySHORT,@countryLONG=countryLONG,@region=region,@city=city,@isp=isp  FROM tbllocation where @ipNO <= ipTO
    INSERT INTO  #tempResult(ipNO,countrySHORT,countryLong,region,city,isp) VALUES (@ipNO,@countrySHORT,@countryLong,@region,@city,@isp)
end
SELECT * FROM  #tempResult
GO


code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
cmdStoredProc.CommandText = "sp_GeoInfo"
cmdStoredProc.CommandType = adCmdStoredProc

Set paramId = cmdStoredProc.CreateParameter("@ipNrs", adVarChar, adParamInput)
paramId.Size = 255
paramId.Value = "21355324;32424234;"
cmdStoredProc.Parameters.Append paramId
set rstStoredProc = cmdStoredProc.Execute

while not rstStoredProc.EOF
    response.write rstStoredProc(0) & "<br>"
    rstStoredProc.movenext
wend

error:
ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

Wanneer ik de code uitvoer in de query analyser gaat alles goed, waarom krijg ik geen resultset terug van de sp ?

Ik begrijp er niets van, moet ik mischien anders de execute doen ??

Wie o Wie ?

Wat niet kan is nog nooit gebeurd


  • whoami
  • Registratie: December 2000
  • Laatst online: 23:32
Moet je niet Open() oid doen als je een recordset wilt terugkrijgen?

https://fgheysels.github.io/


  • Nexopheus
  • Registratie: Juni 2001
  • Laatst online: 28-01 13:50
Gebeurt ook wel :
code:
1
2
3
4
5
Set cnnStoredProc = Server.CreateObject("ADODB.Connection")
cnnStoredProc.Open "Provider=SQLOLEDB;Data Source=(LOCAL);" _
    & "Initial Catalog=ip2location;User Id=******;Password=*****;"
Set cmdStoredProc = Server.CreateObject("ADODB.Command")
cmdStoredProc.ActiveConnection = cnnStoredProc

[ Voor 9% gewijzigd door Nexopheus op 16-04-2004 14:24 ]

Wat niet kan is nog nooit gebeurd


  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
Heb je wel een connection object ingesteld op het command object?
Je kunt hem eventueel ook met de execute meegeven.

  • Nexopheus
  • Registratie: Juni 2001
  • Laatst online: 28-01 13:50
Ehh, ja dus :)

Wat niet kan is nog nooit gebeurd


  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
Dat was sneaky hoor, nog even snel de relevante code erbij plaatsen ;)

Mijn doorgaans al niet te intelligente image wordt nu nog verder de grond in geboord. :*)

  • faabman
  • Registratie: Januari 2001
  • Laatst online: 08-08-2024
lijkt me dat je in ieder geval in je SP ff set nocount = on (of wats het nou zonder =) moet doen...

Op zoek naar een baan als Coldfusion webdeveloper? Mail me!


  • Nexopheus
  • Registratie: Juni 2001
  • Laatst online: 28-01 13:50
bigbeng schreef op 16 april 2004 @ 14:29:
Dat was sneaky hoor, nog even snel de relevante code erbij plaatsen ;)

Mijn doorgaans al niet te intelligente image wordt nu nog verder de grond in geboord. :*)
Sorry 8)

Wat niet kan is nog nooit gebeurd


  • Nexopheus
  • Registratie: Juni 2001
  • Laatst online: 28-01 13:50
faabman schreef op 16 april 2004 @ 14:29:
lijkt me dat je in ieder geval in je SP ff set nocount = on (of wats het nou zonder =) moet doen...
Kun je dit toelichten ? Wat doet dit precies ?

Wat niet kan is nog nooit gebeurd


  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
Een stored procedure geeft in principe het resultaat door van de eerste query. In jouw geval dus de INSERT. Dit heeft geen recordset.

Als je SET NOCOUNT ON doet, dan wordt je select statement doorgegeven aan je command object.

edit:

dit doe je dus in je stored procedure...

[ Voor 12% gewijzigd door bigbeng op 16-04-2004 14:33 ]


  • faabman
  • Registratie: Januari 2001
  • Laatst online: 08-08-2024
Nexopheus schreef op 16 april 2004 @ 14:30:
[...]


Kun je dit toelichten ? Wat doet dit precies ?
uit booksonline
SET NOCOUNT
Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results.

Syntax
SET NOCOUNT { ON | OFF }

Remarks
When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.

The @@ROWCOUNT function is updated even when SET NOCOUNT is ON.

SET NOCOUNT ON eliminates the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. When using the utilities provided with Microsoft® SQL Server™ to execute queries, the results prevent "nn rows affected" from being displayed at the end Transact-SQL statements such as SELECT, INSERT, UPDATE, and DELETE.

For stored procedures that contain several statements that do not return much actual data, this can provide a significant performance boost because network traffic is greatly reduced.

The setting of SET NOCOUNT is set at execute or run time and not at parse time.
edit:

spuit 11 10 8)7

[ Voor 5% gewijzigd door faabman op 16-04-2004 14:43 ]

Op zoek naar een baan als Coldfusion webdeveloper? Mail me!


  • Nexopheus
  • Registratie: Juni 2001
  • Laatst online: 28-01 13:50
_/-\o_

Werkt.
Thx

Wat niet kan is nog nooit gebeurd


  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
faabman schreef op 16 april 2004 @ 14:35:
[...]


uit booksonline


[...]


edit:

spuit 11 8)7
Hehe, ik moet zeggen dat jouw copy/paste uit booksonline een waarheidsgetrouwer beeld schetst van wat er onder de motorkap gebeurt. Je mag jezelf dus best spuit 10 noemen ;)
Pagina: 1