不允许操作...... [英] Operation is not allowed...

查看:103
本文介绍了不允许操作......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:对象关闭时不允许操作。

代码行如下。我无法想象为什么对象会被关闭

它会说它会是,我刚刚在线上打开它。这是一个更大的循环中的所有
,但是循环似乎工作正常,其中的其他

插入语句似乎没问题。有什么建议吗?


Dim cmsRS,cmsSQL

Dim insRS,insSQL

设置cmsRS = Server.CreateObject( " ADODB.Recordset")

设置insRS = Server.CreateObject(" ADODB.Recordset")

cmsSQL =" SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber =''" &

Request.Form(" ref"& intR)& "''AND ClientCode =''CMSNY''"


cmsRS.Open cmsSQL," DSN = kasecure1; uid = sa; pwd = pcbs"


如果不是cmsRS.EOF那么

insSQL =" INSERT INTO CMS(FileNumber,StatusDate,StatusTime,

StatusComment)VALUES(''' ;& Request.Form(" ref"& intR)&"'',''"&

Request.Form(" sd"& intR&" ; _"& intsc&"'',''"& adstime&"'',''检查

日期已设为& isd& "'')"


''/开始问题

insRS.Open insSQL,DSN = kasecure1; uid = sa; pwd = pcbs ;

insRS.Close''错误在这条线上

''/结束问题

结束如果


cmsRS.Close

设置cmsRS =没什么

设置insRS = Nothing

I''m getting an error: "Operation is not allowed when the object is closed."
on the lines of code below. I can''t imagine why the object would be closed
where it says it will be, I''ve just opened it on the line before. This is
all within a larger loop, but the loop seems to be working fine and other
insert statements within it seem ok. Any suggestions?

Dim cmsRS, cmsSQL
Dim insRS, insSQL

Set cmsRS = Server.CreateObject("ADODB.Recordset")
Set insRS = Server.CreateObject("ADODB.Recordset")

cmsSQL = "SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber = ''" &
Request.Form("ref" & intR) & "'' AND ClientCode = ''CMSNY''"

cmsRS.Open cmsSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"

If NOT cmsRS.EOF Then
insSQL = "INSERT INTO CMS (FileNumber, StatusDate, StatusTime,
StatusComment) VALUES(''" & Request.Form("ref" & intR) & "'', ''" &
Request.Form("sd" & intR & "_" & intsc & "'', ''" & adstime & "'', ''Inspection
Date has been set for " & isd & "'')"

'' / Begin Problem
insRS.Open insSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"
insRS.Close '' Errors on this line
'' / End Problem
End If

cmsRS.Close
Set cmsRS = Nothing
Set insRS = Nothing

推荐答案

尝试传球在打开记录集的有效连接对象中,而不是

连接字符串。


Jeff


" ;詹姆斯贝克 < CP ****** @ hotmail.com>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP09.phx.gbl ...
try passing in a valid connection object to the recordset open, instead of a
connection string.

Jeff

"James Baker" <cp******@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
我得到了错误:当对象是
关闭时,不允许操作。在下面的代码行。我无法想象为什么这个物体会在它所说的那个地方被关闭,我刚刚在线上开了它。这是一个更大的循环,但循环似乎工作正常,其中的其他
插入语句似乎没问题。有什么建议吗?

Dim cmsRS,cmsSQL
DIM insRS,insSQL
设置cmsRS = Server.CreateObject(" ADODB.Recordset")
设置insRS = Server.CreateObject(" ADODB.Recordset")

cmsSQL =" SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber =''" &
Request.Form(" ref"& intR)& "''AND ClientCode =''CMSNY''"

cmsRS.Open cmsSQL,DSN = kasecure1; uid = sa; pwd = pcbs"

如果NOT cmsRS.EOF然后
insSQL =" INSERT INTO CMS(FileNumber,StatusDate,StatusTime,
StatusComment)VALUES(''"& Request.Form(" ref"& intR)& ;"'',''"&
Request.Form(" sd"& intR&" _"& intsc&"'',''"& adstime &"'',
''检查日期已设置为& isd&'')"

''/开始问题
insRS.Open insSQL,DSN = kasecure1; uid = sa; pwd = pcbs
insRS.Close''此行错误
''/ End问题
结束如果
cmsRS.Close
设置cmsRS = Nothing
设置insRS = Nothing
I''m getting an error: "Operation is not allowed when the object is closed." on the lines of code below. I can''t imagine why the object would be closed where it says it will be, I''ve just opened it on the line before. This is
all within a larger loop, but the loop seems to be working fine and other
insert statements within it seem ok. Any suggestions?

Dim cmsRS, cmsSQL
Dim insRS, insSQL

Set cmsRS = Server.CreateObject("ADODB.Recordset")
Set insRS = Server.CreateObject("ADODB.Recordset")

cmsSQL = "SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber = ''" &
Request.Form("ref" & intR) & "'' AND ClientCode = ''CMSNY''"

cmsRS.Open cmsSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"

If NOT cmsRS.EOF Then
insSQL = "INSERT INTO CMS (FileNumber, StatusDate, StatusTime,
StatusComment) VALUES(''" & Request.Form("ref" & intR) & "'', ''" &
Request.Form("sd" & intR & "_" & intsc & "'', ''" & adstime & "'', ''Inspection Date has been set for " & isd & "'')"

'' / Begin Problem
insRS.Open insSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"
insRS.Close '' Errors on this line
'' / End Problem
End If

cmsRS.Close
Set cmsRS = Nothing
Set insRS = Nothing



确定。


(a)停止使用DSN( http://www.aspfaq.com/2126)


(b )停止使用ADODB.Recordset( http://www.aspfaq.com/2191),特别是对于

影响数据。


(c)不要随意将用户输入插入到SQL字符串中...搜索

google groups forSQL Injection理解原因。

(d)使用存储过程,如果这是SQL Server

http://www.aspfaq.com/2201)


(e)告诉我们使用的数据库和版本,所以我们没有必要猜测( http://www.aspfaq.com/5009)


(f)请给我们完整的规格,包括DDL,样本数据,期望

结果( http://www.aspfaq.com/ 5006)


(g)不要分开日期和时间......那是为了什么目的?你在VARCHAR专栏中存储日期和时间值吗?


为什么不尝试这样的方法呢?


存储过程:


CREATE PROCEDURE dbo.InsertFile

@fn VARCHAR(12),

@dt VARCHAR(12),

@tm VARCHAR(12),

@comment VARCHAR(255)

AS

BEGIN

套装NOCOUNT ON

如果出售



SELECT 1

FROM TblOrder

WHERE FileNumber = @fn

AND ClientCode =''CMSNY''



INSERT CMS



FileNumber,

StatusDate,

StatusTime,

状态评论



SELECT

@fn,

@ dt,

@ tm,

@comment

END

GO


ASP代码:


fn =替换(Request.Form(" ref"& intR),"''","''''")

dt = Replac E(的Request.Form(QUOT; SD" &安培; intR& " _" &安培; intsc),"''","''''")

set conn = CreateObject(" ADODB.Connection")

conn.open "<在这里使用真实的连接字符串>"

sql =" EXEC dbo.InsertFile" &安培; _

" @fn =''" &安培; fn& "," &安培; _

" @dt =''" &安培; dt& "," &安培; _

" @tm =''" &安培;广告时间& "," &安培; _

" @comment =''检验日期已设定为 &安培; isd& "''"

conn.execute sql ,, 129

conn.close:set conn = nothing


- -
http://www.aspfaq.com/

(反向回复地址。)


" James Baker" < CP ****** @ hotmail.com>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP09.phx.gbl ...
OK.

(a) stop using a DSN (http://www.aspfaq.com/2126).

(b) stop using ADODB.Recordset (http://www.aspfaq.com/2191), especially for
AFFECTING data.

(c) don''t just arbitrarily insert user input into a SQL string... search
google groups for "SQL Injection" to understand why.

(d) use a stored procedure, if this is SQL Server
(http://www.aspfaq.com/2201).

(e) tell us what database and version you are using, so we don''t have to
guess (http://www.aspfaq.com/5009).

(f) please give us complete specs, including DDL, sample data, desired
results (http://www.aspfaq.com/5006).

(g) don''t separate date and time... what is the purpose of that? Are you
storing date and time values in VARCHAR columns?

Why don''t you try an approach like this instead...

Stored procedure:

CREATE PROCEDURE dbo.InsertFile
@fn VARCHAR(12),
@dt VARCHAR(12),
@tm VARCHAR(12),
@comment VARCHAR(255)
AS
BEGIN
SET NOCOUNT ON
IF EXISTS
(
SELECT 1
FROM TblOrder
WHERE FileNumber = @fn
AND ClientCode = ''CMSNY''
)
INSERT CMS
(
FileNumber,
StatusDate,
StatusTime,
StatusComment
)
SELECT
@fn,
@dt,
@tm,
@comment
END
GO

ASP code:

fn = Replace(Request.Form("ref" & intR), "''", "''''")
dt = Replace(Request.Form("sd" & intR & "_" & intsc), "''", "''''")
set conn = CreateObject("ADODB.Connection")
conn.open "< use a real connection string here >"
sql = "EXEC dbo.InsertFile " & _
"@fn=''" & fn & "''," & _
"@dt=''" & dt & "''," & _
"@tm=''" & adstime & "''," & _
"@comment=''Inspection Date has been set for " & isd & "''"
conn.execute sql,,129
conn.close: set conn = nothing

--
http://www.aspfaq.com/
(Reverse address to reply.)


"James Baker" <cp******@hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
我得到了错误:当对象是
关闭时,不允许操作。在下面的代码行。我无法想象为什么这个物体会在它所说的那个地方被关闭,我刚刚在线上开了它。这是一个更大的循环,但循环似乎工作正常,其中的其他
插入语句似乎没问题。有什么建议吗?

Dim cmsRS,cmsSQL
DIM insRS,insSQL
设置cmsRS = Server.CreateObject(" ADODB.Recordset")
设置insRS = Server.CreateObject(" ADODB.Recordset")

cmsSQL =" SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber =''" &
Request.Form(" ref"& intR)& "''AND ClientCode =''CMSNY''"

cmsRS.Open cmsSQL,DSN = kasecure1; uid = sa; pwd = pcbs"

如果NOT cmsRS.EOF然后
insSQL =" INSERT INTO CMS(FileNumber,StatusDate,StatusTime,
StatusComment)VALUES(''"& Request.Form(" ref"& intR)& ;"'',''"&
Request.Form(" sd"& intR&" _"& intsc&"'',''"& adstime &"'',
''检查日期已设置为& isd&'')"

''/开始问题
insRS.Open insSQL,DSN = kasecure1; uid = sa; pwd = pcbs
insRS.Close''此行错误
''/ End问题
结束如果
cmsRS.Close
设置cmsRS = Nothing
设置insRS = Nothing
I''m getting an error: "Operation is not allowed when the object is closed." on the lines of code below. I can''t imagine why the object would be closed where it says it will be, I''ve just opened it on the line before. This is
all within a larger loop, but the loop seems to be working fine and other
insert statements within it seem ok. Any suggestions?

Dim cmsRS, cmsSQL
Dim insRS, insSQL

Set cmsRS = Server.CreateObject("ADODB.Recordset")
Set insRS = Server.CreateObject("ADODB.Recordset")

cmsSQL = "SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber = ''" &
Request.Form("ref" & intR) & "'' AND ClientCode = ''CMSNY''"

cmsRS.Open cmsSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"

If NOT cmsRS.EOF Then
insSQL = "INSERT INTO CMS (FileNumber, StatusDate, StatusTime,
StatusComment) VALUES(''" & Request.Form("ref" & intR) & "'', ''" &
Request.Form("sd" & intR & "_" & intsc & "'', ''" & adstime & "'', ''Inspection Date has been set for " & isd & "'')"

'' / Begin Problem
insRS.Open insSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"
insRS.Close '' Errors on this line
'' / End Problem
End If

cmsRS.Close
Set cmsRS = Nothing
Set insRS = Nothing



James Baker写道:
James Baker wrote:
我得到了错误:当对象关闭时,不允许操作。在下面的代码行。我无法想象为什么对象
会在它所说的地方被关闭,我之前只是在
线上打开它。这都在一个更大的循环中,但循环似乎正常工作,其中的其他插入语句似乎没问题。任何
建议?

Dim cmsRS,cmsSQL
DIM insRS,insSQL

设置cmsRS = Server.CreateObject(" ADODB.Recordset")
设置insRS = Server.CreateObject(" ADODB.Recordset")


由于你向数据库发出多个命令,你应该使用

a single Connection对象而不是为每个

命令打开一个新连接:

Dim cn

设置cn = Server.CreateObject (ADODB.Connection)

cn.Open" DSN = kasecure1; uid = sa; pwd = pcbs"


BTW,它是一个将sa用于您的应用程序的可怕想法。创建一个具有有限权限的sql

登录并使用它而不是sa。


此外,你应该使用OLEDB而不是过时的ODBC。


cn.Open" Provider = SQLOLEDB;" &安培; _

" Data Source = your_server_name;" &安培; _

" Initial Catalog = the_database;" &安培; _

"用户ID = xxxx;密码= xxxx"

cmsSQL =" SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber =
''" &安培; Request.Form(ref& intR)& "''AND ClientCode =''CMSNY''"

cmsRS.Open cmsSQL,cn ,,, 1''1 = adCmdText


如果NOT cmsRS.EOF然后
insSQL =" INSERT INTO CMS(FileNumber,StatusDate,StatusTime,
StatusComment)VALUES(''"& Request.Form(" ref"& intR)& ;"'',''"&
Request.Form(" sd"& intR&" _"& intsc&"'',''"& adstime &"'',
''检查日期已设置为& isd&'')"


有没有机会在所有这个查询都将返回记录?不是吗?那么为什么

创建并打开一个昂贵的记录集?

''/开始问题
insRS.Open insSQL," ; DSN = kasecure1; uid = sa; pwd = pcbs"
insRS.Close''此行错误
I''m getting an error: "Operation is not allowed when the object is
closed." on the lines of code below. I can''t imagine why the object
would be closed where it says it will be, I''ve just opened it on the
line before. This is all within a larger loop, but the loop seems to
be working fine and other insert statements within it seem ok. Any
suggestions?

Dim cmsRS, cmsSQL
Dim insRS, insSQL

Set cmsRS = Server.CreateObject("ADODB.Recordset")
Set insRS = Server.CreateObject("ADODB.Recordset")
Since you are issuing multiple commands to the database, you should be using
a single Connection object instead of opening a new connection for each
command:

Dim cn
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "DSN=kasecure1;uid=sa;pwd=pcbs"

BTW, it is a horrible idea to use sa for your applications. Create a sql
login with limited permissions and use that instead of sa.

Also, you should use OLEDB instead of the obsolete ODBC.

cn.Open "Provider=SQLOLEDB;" & _
"Data Source=your_server_name;" & _
"Initial Catalog=the_database;" & _
"User ID = xxxx;Password=xxxx"

cmsSQL = "SELECT ClientsFileNumber FROM TblOrder WHERE FileNumber =
''" & Request.Form("ref" & intR) & "'' AND ClientCode = ''CMSNY''"
cmsRS.Open cmsSQL, cn,,,1 ''1=adCmdText

If NOT cmsRS.EOF Then
insSQL = "INSERT INTO CMS (FileNumber, StatusDate, StatusTime,
StatusComment) VALUES(''" & Request.Form("ref" & intR) & "'', ''" &
Request.Form("sd" & intR & "_" & intsc & "'', ''" & adstime & "'',
''Inspection Date has been set for " & isd & "'')"

Is there any chance at all that this query will return records? No? So why
create and open an expensive recordset?
'' / Begin Problem
insRS.Open insSQL, "DSN=kasecure1;uid=sa;pwd=pcbs"
insRS.Close '' Errors on this line




由于您没有从查询,当然你不要t

此时有一个开放的重新设置。摆脱第二个记录集的createobject

语句并使用它来执行一个查询b $ b不返回记录:


cn.Execute insSQL ,, 129''129 = adCmdText(1)+ adExecuteNoRecords(128)


HTH,

Bob Barrows

-

Microsoft MVP - ASP / ASP.NET

请回复到新闻组。我的From

标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。



Since there were no records returned from your query, of course you don''t
have an open re cordset at this point. Get rid of that createobject
statement for the second recordset and use this to execute a query that does
not return records:

cn.Execute insSQL,,129 ''129=adCmdText(1)+adExecuteNoRecords(128)

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get a
quicker response by posting to the newsgroup.


这篇关于不允许操作......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆