[Resolvido] Transações em ASP SQLServer O que há de errado
tenho duas tabelas (na verdade mais DO QUE ISTO, MAIS COMECEMOS POR AI)que preciso preencher, agenda_prof_qtd_atender E agenda_prof_atend, e estou tentando usar transasções no asp com os seguinte código:
ASP
<% 'Option Explicit
On Error Resume Next
Dim oConn, oRs
Dim Maximo
Dim Atual
Dim Inserir
Dim SQUERY
Inserir = 0
set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open MM_conexao2_STRING
if err.Number <> 0 then
response.Write("<BR>Erro ao abrir conexão...")
response.Write("Descrição do erro: " & err.Description & "...<BR>")
ObjectContext.SetAbort()
Response.End()
else
Response.Write("A conexão foi aberta com exito...<BR>")
ObjectContext.SetComplete()
'Paciente, Data, Horário_Id
' Prof_q_Encaminhou, Cnes_enc,
Response.Write("<P class='chapeu'>Paciente: "&session("nUsuarioNome")&"</P>")
set oRS = Server.CreateObject("ADODB.RecordSet")
SQUERY = "select * from agenda_prof_qtd_atender where horario_id = " + request.QueryString("horario_id") + " and data_consulta = '" + request.QueryString("data") + "'"
oRS.open SQUERY, oConn, 3
RESPONSE.Write( SQUERY+ " "+ Cstr(oRS.RecordCount)+ "<br>")
if (oRS.RecordCount > 0) then
Maximo = Cstr(oRS.Fields.Item("num_max").Value)
Atual = Cstr(oRS.Fields.Item("num_atual").Value)
RESPONSE.Write( "<br> Maximo = "+Maximo+ " <= M A=> Atual =" + Atual + "<br>")
SQUERY = "UPDATE agenda_prof_qtd_atender SET num_atual = num_atual + 1 where horario_id = " + request.QueryString("horario_id") + " and data_consulta = '" + request.QueryString("data") + "' "
RESPONSE.Write( SQUERY+ "<br>")
if (MAXIMO <> "") AND (Maximo > Atual) then
oRS.Execute SQUERY
Inserir = 1
else
OnTransactionAbort()
end if
else
SQUERY = "INSERT INTO agenda_prof_qtd_atender (horario_id, data_consulta, num_max, num_atual ) VALUES (" + request.QueryString("horario_id") + ", '" + request.QueryString("data") + "','" + request.QueryString("num_max_pac") + "',1 )"
'RESPONSE.Write( SQUERY+ "<br>")
oRS.Execute SQUERY
Inserir = 1
end if
if (Inserir <> 0 ) then
SQUERY = "INSERT INTO agenda_prof_atend (co_usuario, data_consulta, horario_id) VALUES ('"+session("nUsuarioID")+"', '"+ request.QueryString("data") + "', "+ request.QueryString("horario_id")+ ")"
'RESPONSE.Write( SQUERY+ " LINHA 58<br>")
oConn.Execute SQUERY
end if
if err.Number <> 0 Then
Response.Write "<BR>Erro ao executar a comandos...N="+Cstr(err.Number)+"<BR>"
Response.Write "<BR>Descrição do erro: " & err.Description & "...<BR>"
oRS.Close
oConn.Close
Set oConn = Nothing
ObjectContext.SetAbort
Response.End
else
Response.Write "<BR>Comandos realizados com êxito...<BR>"
ObjectContext.SetComplete
end If
end if
oRS.Close
oConn.Close
Response.Write "<BR>A conexão foi fechada com êxito...<BR>"
Set oRS = Nothing
set oConn = Nothing
Response.Write "<BR>O teste foi concluído com êxito...<BR>"
Sub OnTransactionCommit()
Response.Write "<p><B>A transação foi realizada</B>."
Response.Write( SQUERY + "<br>")
Response.Write "Esta mensagem é proveniente de "
Response.Write "Manipulador de eventos OnTransactionCommit()."
End Sub
Sub OnTransactionAbort()
Response.Write "<p ><B>A transação foi anulada</B>."
Response.Write( SQUERY + "<br>")
Response.Write "Esta mensagem é proveniente de "
Response.Write "Manipulador de eventos OnTransactionAbort()."
End Sub
%>
e consigo ver com as linhas que coloquei pra tentar achar o erro o seguinte:
A conexão foi aberta com exito...
Paciente: ANA UMBELINA DA SILVA XAVIER
select * from agenda_prof_qtd_atender where horario_id = 2 and data_consulta = '2007/11/2' 0
Erro ao executar a comandos...N=438
Descrição do erro: O objeto não dá suporte para a propriedade ou método...
A transação foi anulada.INSERT INTO agenda_prof_atend (co_usuario, data_consulta, horario_id) VALUES ('1600135272000005', '2007/11/2', 2)
Esta mensagem é proveniente de Manipulador de eventos OnTransactionAbort().
ALGUEM PODE ME AJUDAR A DESCUBRIR QUAL O ERRO.
Discussão (15)
Carregando comentários...