• Lunes 6 de Mayo de 2024, 18:32

Autor Tema:  Manejo De Transacciones  (Leído 1937 veces)

juravi

  • Miembro activo
  • **
  • Mensajes: 94
    • Ver Perfil
    • http://spaces.msn.com/members/ingjuan
Manejo De Transacciones
« en: Jueves 2 de Diciembre de 2004, 21:42 »
0
Hola. diran que yo si pregunto, pero es q si me salen errores que yo ni sabia q existian.
mi problema es el siguiente; estoy usando begintrans,committrans y RollbackTrans todo funciona bien pero siempre hay un pero. Cuando ocurre un error donde no se a entrado al begintrans, me sale un error con el rollbacktrans.
COMO HAGO PARA QUE EL SISTEMA SE DE CUENTA QUE NO SE HA EJECTUTADO UN BEGINTRANS( en el manejador de error. donde esta el rollback).
miren. este es parte de un codigo


Public Sub MUESTRA()
On Error GoTo Err
   Dim cnn1 As ADODB.Connection
   Dim rstTitles As ADODB.Recordset
   Dim strCnn As String
   Dim strTitle As String
   Dim strMessage As String

   ' Open connection.
      strCnn = "Provider=sqloledb;" & _
      "Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
   Set cnn1 = New ADODB.Connection
   cnn1.Open strCnn

   ' Open Titles table.
   Set rstTitles = New ADODB.Recordset
   rstTitles.CursorType = adOpenDynamic
   rstTitles.LockType = adLockPessimistic
   rstTitles.Open "titles", cnn1, , , adCmdTable
   
   rstTitles.MoveFirst
   cnn1.BeginTrans

   ' Loop through recordset and ask user if she wants
   ' to change the type for a specified title.
   Do Until rstTitles.EOF
      If Trim(rstTitles!Type) = "psychology" Then
         strTitle = rstTitles!title
         strMessage = "Title: " & strTitle & vbCr & _
         "Change type to self help?"

         ' Change the title for the specified
         ' employee.
         If MsgBox(strMessage, vbYesNo) = vbYes Then
            rstTitles!Type = "self_help"
            rstTitles.Update
         End If
      End If

         rstTitles.MoveNext
   Loop
      cnn1.CommitTrans
EXIT SUB
  ERR:
 CALL   ManejadordeError
End Sub

Function ManejadordeError()
  MsgBox "El servidor SQL Server está presentando problemas" + Chr(10) + _
  "Causas posibles:" + Chr(10) + _
  "-Puede que haya problemas con la conexion de la red" + Chr(10) + _
  "-Puede ser que la Base de Datos o alguna de sus tablas tenga problemas de acceso" + Chr(10) + _
  "Por favor localize al Adminstrador del Sistema lo antes posible, para que corrija el error" + Chr(10) + _
  CStr(Err.Number) & "  " & Err.Description, vbInformation
 
CnSQLconexion.RollbackTrans
 end function

SE LOS AGRADECERIA MUCHO, Y DISCULPEN Q MOLESTE DEMASIADO.
SALUDOS
El Fin justifica los Medios
 _______________________
ﻞυגανι.Corp [The Designer]
<a href=\'mailto]No sé el secreto para llegar al éxito, pero sé que tratar de agradar a todos es lo que te llevará al fracaso... Piénsalo!!![/color]

Jose Arriagada

  • Miembro MUY activo
  • ***
  • Mensajes: 373
    • Ver Perfil
Re: Manejo De Transacciones
« Respuesta #1 en: Jueves 2 de Diciembre de 2004, 22:41 »
0
USA UNA VARIABLE DE CONTROL PARA SABER SI YA PASO POR EL BEGIN TRANS



Public Sub MUESTRA()
On Error GoTo Err
Dim cnn1 As ADODB.Connection
Dim rstTitles As ADODB.Recordset
Dim strCnn As String
Dim strTitle As String
Dim strMessage As String
DIM FLAG AS INTEGER


FLAG=0 'No hay inicio de BEGIN TRANS
' Open connection.
strCnn = "Provider=sqloledb;" & _
"Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn

' Open Titles table.
Set rstTitles = New ADODB.Recordset
rstTitles.CursorType = adOpenDynamic
rstTitles.LockType = adLockPessimistic
rstTitles.Open "titles", cnn1, , , adCmdTable

rstTitles.MoveFirst
cnn1.BeginTrans

FLAG=1 'YA ENTRO AL BEGIN

' Loop through recordset and ask user if she wants
' to change the type for a specified title.
Do Until rstTitles.EOF
If Trim(rstTitles!Type) = "psychology" Then
strTitle = rstTitles!title
strMessage = "Title: " & strTitle & vbCr & _
"Change type to self help?"

' Change the title for the specified
' employee.
If MsgBox(strMessage, vbYesNo) = vbYes Then
rstTitles!Type = "self_help"
rstTitles.Update
End If
End If

rstTitles.MoveNext
Loop
cnn1.CommitTrans
EXIT SUB
ERR:
CALL ManejadordeError
End Sub

Function ManejadordeError()
MsgBox "El servidor SQL Server está presentando problemas" + Chr(10) + _
"Causas posibles:" + Chr(10) + _
"-Puede que haya problemas con la conexion de la red" + Chr(10) + _
"-Puede ser que la Base de Datos o alguna de sus tablas tenga problemas de acceso" + Chr(10) + _
"Por favor localize al Adminstrador del Sistema lo antes posible, para que corrija el error" + Chr(10) + _
CStr(Err.Number) & " " & Err.Description, vbInformation

IF FLAG=1 THEN
    CnSQLconexion.RollbackTrans
END IF

end function

juravi

  • Miembro activo
  • **
  • Mensajes: 94
    • Ver Perfil
    • http://spaces.msn.com/members/ingjuan
Re: Manejo De Transacciones
« Respuesta #2 en: Viernes 3 de Diciembre de 2004, 01:49 »
0
:comp: hey gracias amigo... me funciono.......
como no se me habia ocurrido.......jajajaajjajaja..... :kicking:
 :devil:
El Fin justifica los Medios
 _______________________
ﻞυגανι.Corp [The Designer]
<a href=\'mailto]No sé el secreto para llegar al éxito, pero sé que tratar de agradar a todos es lo que te llevará al fracaso... Piénsalo!!![/color]