I have this sub and this SP. SOMETIMES I get the message:
"THE OPERATION IS NOT ALLOWED WHEN THE OBJECT IS CLOSED"
I'm using SQL Server 7 and IIS on a Windows 2000 Server.
I can't understand why it happens only sometimes. And when it fails I just refresh the page and it works with the very same data and parameters.
I have several other similar Subs running similar SP's and I don't have any problems. All the other SP's use the sp_Download procedure.
That's the Sub:
*********************************************************
Sub btnCartanClick
On Error Resume Next
dim id, ncartao, oper, nome, comp
id = parent("frmMain".inpCH05CardHolderID.value
ncartao = inpCartao.value
oper = parent("frmMain".operador.value
nome = inpCH11Visitee.value
comp = vis.inpCH11UF20.value
dim server
server = parent("frmMain".ServerName.value
If ncartao <> "" Then
If inpCH11FirstName.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Nome' deve ser preenchido"
Exit Sub
ElseIf inpCHPreferredName.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Documento' deve ser preenchido"
Exit Sub
ElseIf inpCH11Company.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Empresa' deve ser preenchido"
Exit Sub
'ElseIf inpCH11UF19.value <= 0 Then
'parent("frmGlobal".SetStationMessage "O campo 'Fone para contato' deve ser preenchido"
'Exit Sub
ElseIf inpCH11Visitee.value = "" and vis.inpCH11UF20.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Visitado ou Visitado - Complemento' deve ser preenchido"
Exit Sub
Else
dim objConn, rs, sql, strConn
set objConn = CreateObject("ADODB.Connection"
strConn = "Provider=SQLOLEDB;Server="&server&";Database=CMS;UID=cms;PWD=ebi;"
objConn.open strConn
sql = "EXEC sp_AssociaCartaoVisitante "&id&", "&ncartao&", '"&oper&"', '"&nome&"', '"&comp&"' "
objConn.execute(sql)
'####I SEE THE MESSAGE USING THIS CODE:
If Err.Number <> 0 Then
parent("frmGlobal".SetStationMessage Err.Description
Err.Clear
Exit Sub
End If
objConn.Close
set objConn = Nothing
'Salva o cadastro e atualiza a tela
SaveRecord
window.parent.navigate "
End If
End If
End Sub
*********************************************************
And that's the SP:
#########################################################
--Script para automatizar o fornecimento de crachás de visitantes:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'sp_AssociaCartaoVisitante' AND type = 'P')
DROP PROCEDURE sp_AssociaCartaoVisitante
GO
USE CMS
GO
CREATE PROCEDURE sp_AssociaCartaoVisitante
@ID nchar(6),
@CARD nchar(8),
@OPER nchar(10),
@VISITADO varchar(50),
@VISITADOCOMP varchar(500)
WITH ENCRYPTION
AS
SET NOCOUNT ON
--Grava o número real do cartão a ser associado
DECLARE @cartaoreal nchar(8)
SET @cartaoreal = (SELECT CardNumber FROM TB_CartaoVisitantes WHERE CardAlias = @CARD)
--SET @cartaoreal = @CARD
IF EXISTS (SELECT CardNumber FROM TB_CartaoVisitantes WHERE CardAlias = @CARD)
AND EXISTS (SELECT CardNumber FROM Cards WHERE CardNumber = @cartaoreal)
--IF EXISTS (SELECT CardNumber FROM Cards WHERE CardNumber = @cartaoreal)
BEGIN
IF (SELECT COUNT(*) FROM Cards WHERE CardHolderID = @ID AND CardStateID = 0) = 0
BEGIN
IF ((SELECT CardHolderID FROM Cards WHERE CardNumber = @cartaoreal) <> 0
AND (SELECT CardStateID FROM Cards WHERE CardNumber = @cartaoreal) <> 0)
OR (SELECT CardHolderID FROM Cards WHERE CardNumber = @cartaoreal) = 0
BEGIN
--Associa o cartão e efetua download:
--Marca o CardHolder para Download e o coloca Ativo:
UPDATE CardHolders
SET HolderDownloadRequired = 1 WHERE CardHolderID = @ID
UPDATE CardHolders
SET CHStateID = 0 WHERE CardHolderID = @ID
UPDATE CardHolders
SET CHCommencementDateTime = getdate() WHERE CardHolderID = @ID
UPDATE CardHolders
SET CHExpiryDateTime = getdate()+ 1 WHERE CardHolderID = @ID
--Ativa o cartão:
UPDATE Cards
SET CardHolderID = 0 WHERE CardHolderID = @ID
UPDATE Cards
SET CardHolderID = @ID, CardStateID = 0 WHERE CardNumber = @cartaoreal
UPDATE Cards
SET CardCommencementDateTime = getdate() WHERE CardHolderID = @ID
UPDATE Cards
SET CardExpiryDateTime = getdate()+ 1 WHERE CardHolderID = @ID
EXEC sp_Download @cartaoreal, @ID
INSERT INTO TB_VisitantesLog (CardHolderID, NCartao, DataLiberacao, LibPor, Visitado, VisitadoComp)
VALUES(@ID, @cartaoreal, getdate(), @OPER, @VISITADO, @VISITADOCOMP)
UPDATE CardHolders
SET LastModifBy = @OPER, LastModifDateTime = getdate() WHERE CardHolderID = @ID
UPDATE Cards
SET LastModifBy = @OPER, LastModifDateTime = getdate() WHERE CardHolderID = @ID
END
ELSE
RAISERROR ('O cartão já está sendo utilizado', 16, 1)
END
ELSE
RAISERROR ('O visitante possui cartão associado', 16, 1)
END
ELSE
RAISERROR ('Cartão inválido', 16, 1)
GO
###########################################################
Thanks in advance,
André Silva
"THE OPERATION IS NOT ALLOWED WHEN THE OBJECT IS CLOSED"
I'm using SQL Server 7 and IIS on a Windows 2000 Server.
I can't understand why it happens only sometimes. And when it fails I just refresh the page and it works with the very same data and parameters.
I have several other similar Subs running similar SP's and I don't have any problems. All the other SP's use the sp_Download procedure.
That's the Sub:
*********************************************************
Sub btnCartanClick
On Error Resume Next
dim id, ncartao, oper, nome, comp
id = parent("frmMain".inpCH05CardHolderID.value
ncartao = inpCartao.value
oper = parent("frmMain".operador.value
nome = inpCH11Visitee.value
comp = vis.inpCH11UF20.value
dim server
server = parent("frmMain".ServerName.value
If ncartao <> "" Then
If inpCH11FirstName.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Nome' deve ser preenchido"
Exit Sub
ElseIf inpCHPreferredName.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Documento' deve ser preenchido"
Exit Sub
ElseIf inpCH11Company.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Empresa' deve ser preenchido"
Exit Sub
'ElseIf inpCH11UF19.value <= 0 Then
'parent("frmGlobal".SetStationMessage "O campo 'Fone para contato' deve ser preenchido"
'Exit Sub
ElseIf inpCH11Visitee.value = "" and vis.inpCH11UF20.value = "" Then
parent("frmGlobal".SetStationMessage "O campo 'Visitado ou Visitado - Complemento' deve ser preenchido"
Exit Sub
Else
dim objConn, rs, sql, strConn
set objConn = CreateObject("ADODB.Connection"
strConn = "Provider=SQLOLEDB;Server="&server&";Database=CMS;UID=cms;PWD=ebi;"
objConn.open strConn
sql = "EXEC sp_AssociaCartaoVisitante "&id&", "&ncartao&", '"&oper&"', '"&nome&"', '"&comp&"' "
objConn.execute(sql)
'####I SEE THE MESSAGE USING THIS CODE:
If Err.Number <> 0 Then
parent("frmGlobal".SetStationMessage Err.Description
Err.Clear
Exit Sub
End If
objConn.Close
set objConn = Nothing
'Salva o cadastro e atualiza a tela
SaveRecord
window.parent.navigate "
End If
End If
End Sub
*********************************************************
And that's the SP:
#########################################################
--Script para automatizar o fornecimento de crachás de visitantes:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'sp_AssociaCartaoVisitante' AND type = 'P')
DROP PROCEDURE sp_AssociaCartaoVisitante
GO
USE CMS
GO
CREATE PROCEDURE sp_AssociaCartaoVisitante
@ID nchar(6),
@CARD nchar(8),
@OPER nchar(10),
@VISITADO varchar(50),
@VISITADOCOMP varchar(500)
WITH ENCRYPTION
AS
SET NOCOUNT ON
--Grava o número real do cartão a ser associado
DECLARE @cartaoreal nchar(8)
SET @cartaoreal = (SELECT CardNumber FROM TB_CartaoVisitantes WHERE CardAlias = @CARD)
--SET @cartaoreal = @CARD
IF EXISTS (SELECT CardNumber FROM TB_CartaoVisitantes WHERE CardAlias = @CARD)
AND EXISTS (SELECT CardNumber FROM Cards WHERE CardNumber = @cartaoreal)
--IF EXISTS (SELECT CardNumber FROM Cards WHERE CardNumber = @cartaoreal)
BEGIN
IF (SELECT COUNT(*) FROM Cards WHERE CardHolderID = @ID AND CardStateID = 0) = 0
BEGIN
IF ((SELECT CardHolderID FROM Cards WHERE CardNumber = @cartaoreal) <> 0
AND (SELECT CardStateID FROM Cards WHERE CardNumber = @cartaoreal) <> 0)
OR (SELECT CardHolderID FROM Cards WHERE CardNumber = @cartaoreal) = 0
BEGIN
--Associa o cartão e efetua download:
--Marca o CardHolder para Download e o coloca Ativo:
UPDATE CardHolders
SET HolderDownloadRequired = 1 WHERE CardHolderID = @ID
UPDATE CardHolders
SET CHStateID = 0 WHERE CardHolderID = @ID
UPDATE CardHolders
SET CHCommencementDateTime = getdate() WHERE CardHolderID = @ID
UPDATE CardHolders
SET CHExpiryDateTime = getdate()+ 1 WHERE CardHolderID = @ID
--Ativa o cartão:
UPDATE Cards
SET CardHolderID = 0 WHERE CardHolderID = @ID
UPDATE Cards
SET CardHolderID = @ID, CardStateID = 0 WHERE CardNumber = @cartaoreal
UPDATE Cards
SET CardCommencementDateTime = getdate() WHERE CardHolderID = @ID
UPDATE Cards
SET CardExpiryDateTime = getdate()+ 1 WHERE CardHolderID = @ID
EXEC sp_Download @cartaoreal, @ID
INSERT INTO TB_VisitantesLog (CardHolderID, NCartao, DataLiberacao, LibPor, Visitado, VisitadoComp)
VALUES(@ID, @cartaoreal, getdate(), @OPER, @VISITADO, @VISITADOCOMP)
UPDATE CardHolders
SET LastModifBy = @OPER, LastModifDateTime = getdate() WHERE CardHolderID = @ID
UPDATE Cards
SET LastModifBy = @OPER, LastModifDateTime = getdate() WHERE CardHolderID = @ID
END
ELSE
RAISERROR ('O cartão já está sendo utilizado', 16, 1)
END
ELSE
RAISERROR ('O visitante possui cartão associado', 16, 1)
END
ELSE
RAISERROR ('Cartão inválido', 16, 1)
GO
###########################################################
Thanks in advance,
André Silva