简体   繁体   English

未从存储过程中填充经典ASP,ADO,记录集

[英]Classic ASP, ADO, recordset not populating from Stored Procedure

In a Classic ASP script, I have a sql statement that executes a stored procedure: 在经典ASP脚本中,我有一条执行存储过程的sql语句:

sql="exec my_stored_proc"

I then attempt to fill an ADO Recordset object with the results and loop through the recordset. 然后,我尝试用结果填充ADO Recordset对象并遍历记录集。

The stored procedure itself is populating a virtual table and the last line of the procedure returns the results: 存储过程本身正在填充虚拟表,过程的最后一行返回结果:

select tableName, subTable, FieldLabel, total, FieldOrder from @AdmissionsTable

When executed directly from SQL management studio, I get results, but when executed from the ASP page, this line: 直接从SQL Management Studio执行时,我得到结果,但是从ASP页执行时,此行:

do while not rs.eof

results in the error "Operation is not allowed when the object is closed." 导致错误“关闭对象时不允许操作”。

I know it's not because I'm trying to execute a stored proc, because I tested it against another stored proc, and was able to get results into the rs object. 我知道这不是因为我试图执行一个存储的proc,是因为我针对另一个存储的proc对其进行了测试,并且能够将结果输入rs对象。

Is it because I'm using a virtual table? 是因为我正在使用虚拟表吗? Or something else? 或者是其他东西?

Extra code: 额外的代码:

After the sql string is assigned I open the connection, set the rs object, and execute the query: 分配sql字符串后,我打开连接,设置rs对象,并执行查询:

conn.Open strConnection
Set rs = server.createobject("ADODB.Recordset")
rs.open sql, conn

Then comes the error line: 然后出现错误行:

do while not rs.eof

Further update: 进一步更新:

Right after the rs.open line, I added some debug code to response.write "RS Populated," and this line executes. 在rs.open行之后,我向response.write“ RS Populated”添加了一些调试代码,并执行了该行。 But then the error still appears directly after that, so I'm guessing this means that somehow the RS is getting closed right away. 但是随后错误仍然直接出现,因此我猜测这意味着RS立即以某种方式关闭。 Not sure why. 不知道为什么。

Still further update: 进一步更新:

I've at least isolated the problem. 我至少已经隔离了这个问题。 The err object returns "Query timeout" as the error, and rs.ActiveConnection.CommandTimeout returns "30" as my timeout value. err对象返回“查询超时”作为错误,而rs.ActiveConnection.CommandTimeout返回“ 30”作为我的超时值。

The query is large and takes at least 60 seconds to run, so I tried setting rs.ActiveConnection.CommandTimeout = 120, but it still fails and - most maddeningly - it still returns "30" as the timeout value. 该查询很大,至少需要60秒才能运行,因此我尝试将rs.ActiveConnection.CommandTimeout设置为120,但仍然失败,并且-最令人发狂的是-它仍返回“ 30”作为超时值。

If rs.ActiveConnection.CommandTimeout = 120 didn't work to increase the timeout, how can I get that value up? 如果rs.ActiveConnection.CommandTimeout = 120不能用于增加超时,如何增加该值?

Problem solved. 问题解决了。 I had to set the CommandTimeout property at the connection level: 我必须在连接级别设置CommandTimeout属性:

conn.CommandTimeout=120

Now it works. 现在可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM