Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error getting recordset

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hi I am using the following code to execute stored proc and get a recordset, but getting an error that recordset object is closed. Can someone please take a look if there is issue in code:
Thanks!!

<%
var CS_updateConnection = MM_mediakitDB_STRING;
Application("ConnectionProvider") = "MSDASQL";
Application("ConnectionString") = CS_updateConnection;
var Conn = Server.CreateObject("ADODB.Connection");


Conn.Provider = Application("ConnectionProvider");
Conn.Open(Application("ConnectionString"));


////////
var oCmd = Server.CreateObject("ADODB.Command");
oCmd.ActiveConnection = Conn;
oCmd.CommandText = "processAdLink";
oCmd.CommandType = 4;

var p = oCmd.Parameters;
p.Append (oCmd.CreateParameter("@adID",17))
oCmd("@adID") = adID;



var adInfo = Server.CreateObject("ADODB.Recordset")
adInfo_Open (oCmd)

if (!adInfo.EOF) { //Getting error here!!!
var goURL = String(adInfo("goURL"));
var winID = String(adInfo("winID"));
} else {
var adID="failed"
}
adInfo.Close
Conn.Close

%>
 
In the processAdLink, do you have Set Nocount ON.

Ex:

[tt][blue]
Alter Procedure processAdLink
@Param1 ....,
@Param2 ....
As

[!]SET NOCOUNT ON[/!]

Everything else in the stored procedure....
[/blue][/tt]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Well. I didn't say it, but... you should put Set Nocount On in to the stored procedure and then try again. If this works, I will explain WHY it works so that you will understand when it's needed.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
before I make the change... the code used to work when it did not have parameters and was executing stored proc like this:
Conn.exec("processAdLink " + AdID)

Then I added all that code to out adID in a parameter (to avoid SQL injection)
Does that make any difference?
 
Here's what I know. For fact.

Adding Set Nocount On will not, cannot cause any problems in your system. Not having it can cause problems under certain circumstances. In my opinion, every stored procedure should have that line at the top of it. Here's why...

When you have a stored procedure that 'does' a couple things, you will get multiple recordsets returned. The first recordset will have...

1 record affected

The next recordset will have your data.

By including Set NoCount On, the first recordset will not appear so that the only data returned will be the recordset you were expecting.

Does this make sense?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top