Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2004, 10:09 AM
Authorized User
 
Join Date: Feb 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default PROBLEM with calling Procs from ASP codes

PROBLEM with calling Procs from ASP codes:
Any simple stored procs, i.e. without use of temporary tables (#CurTable), do work !
But those with temporary table (e.g. #CurTable) returns closed or bad recordset object
- thus is not working !!
Content of one of these SQLServer procs are as follows:

    PROCEDURE dbo.proc-name
      input parameters
    AS
      declare local varaibles
      initialize local variables
    DECLARE TableCursor CURSOR LOCAL FORWARD_ONLY STATIC FOR
      original SQL-statement
    CREATE TABLE #CurTable(own parameters)
    OPEN TableCursor
    FETCH NEXT FROM TableCursor INTO field-parameters
    WHILE @@FETCH_STATUS = 0
        BEGIN
        compute value of fields for record in '#CurTable'
        INSERT INTO #CurTable(fields-list) VALUES(values-of-fields list)
        reset field values for next '#curTable' record
        FETCH NEXT FROM TableCursor INTO field-parameters
        END
    CLOSE TableCursor
    DEALLOCATE TableCursor
      update last record of '#CurTable' if necessary
    SELECT fields FROM #CurTable WHERE conds ORDER BY sort-fields
    DROP TABLE #CurTable

However, while it works calling from SQLServer Query-Analyser utility Tools,
and from Crystal Reports, can retrieve record set from ASP!
This is the ASP routine:

    Dim rs

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorLocation = adUseServer
    rs.open sql,connstr,adOpenForwardOnly,adLockReadOnly

    Do while not rs.EOF '' This gives error stating this object, rs, is not opened !
    'process a record'
    rs.MoveNext
    Loop
    rs.Close
    Set rs = nothing

THX all!!!

Jorge
__________________
Jorge
 
Old September 23rd, 2004, 12:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You need to use a command object to execute a stored procedure. You can pass the results to a recordset. I don't think you can execute it directly from a recordset.

Brian
 
Old September 23rd, 2004, 02:56 PM
Authorized User
 
Join Date: Feb 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian!
Actually, I did try what you suggest (but had not yet updated the Post)....
Alternatively, using Command object is tried (as several suggestions from forum web sites):

    Dim cmd, cn, sql, rs

    sql = "<proc-name>"

    Set cn = server.CreateObject("ADODB.Connection")
    cn.Open Application("NSIA1_ConnectionString")
    Set cmd = Server.CreateObject("ADODB.Command")
    with cmd
        .ActiveConnection = cn
        .CommandText = sql
        .CommandType = adCmdStoredProc

        .Parameters.Append .CreateParameter("@ReportGroupId",adInteger,adPara mInput,,<1st parameter value>)
        .Parameters.Append .CreateParameter("@CurrentSeason",adInteger,adPara mInput,,<2nd parameter value>)

        .Parameters.Append .CreateParameter("@UserId",adInteger,adParamInput, ,<last parameter value>)
        Set rs = .Execute
    end with
    Set cmd = nothing

    Do while not rs.EOF '' This still gives an error stating this object, rs, is not opened !
      '' proecess a record
      rs.MoveNext
    Loop
    rs.Close()
    Set rs = nothing
    cn.Close()

THX again!

Jorge
 
Old September 23rd, 2004, 04:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Try setting your cmd to nothing after you are done with the recordset. I wonder if that's how the rs gets the connection, and because you set it to nothing, that may cause a problem???

Also, double-check your query. ADO may have a problem with it, even if it works in SQL Server.

Thanks,

Brian
 
Old September 24th, 2004, 03:18 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your stored procedure is probably returning other stuff before the recordset.
Firstly try adding SET NOCOUNT ON after the AS statement at the start of the procedure. If that doesn't fix it try this before you use the recordset:
Code:
Do While RS.state = adStateClosed
  Set RS = RS.NextRecordet()
Loop
Now start using the rcordset.

--

Joe
 
Old September 24th, 2004, 08:30 AM
Authorized User
 
Join Date: Feb 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SOLUTION:
Here's our solution (tested successfully):
(ie Solution to calling Proc with temporary stable from ASP page)
    Dim sql, rs

    sql = "proc-name its-parameter"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.ActiveConnection = Application("NSIA1_ConnectionString")
    rs.LockType = adLockReadOnly
    rs.CursorType = adOpenForwardOnly
    rs.CursorLocation = adUseServer
    rs.Open "SET NOCOUNT ON" '' This statement does the trick !
    rs.open sql

    Do while not rs.EOF
      ''''process current record 'rs'
      rs.movenext
    Loop
    rs.Close()
    Set rs = noting

Also see (MS knowledge Base Article 235340):
http://support.microsoft.com/default...b;en-us;235340

THX to all :) !

Jorge





Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Stored procs with ASP tdaustin Classic ASP Databases 4 June 17th, 2008 01:20 AM
Problem while calling a VB COM DLL in ASP ranee Classic ASP Components 0 December 1st, 2005 09:44 AM
codes about this book: Building An ASP.NET Intrane john.shu General .NET 2 November 28th, 2005 09:51 AM
Why .asp source codes are display on screen? Andraw Classic ASP Basics 0 January 24th, 2005 11:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.