Why can't it find the BeginTransaction line????

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Why can't it find the BeginTransaction line????

    Easy, you start the transaction INSIDE the try, and the OUTSIDE catch (the
    try portion is like a sub-function and have diferent scope, that is the
    reason) don't can see that, simply change to:

    StartTransaction
    try
    TheCode
    Commit
    catch
    RollbackTransaction
    finally
    CloseConnections
    end


    Mamcx Guest

  2. Similar Questions and Discussions

    1. need to find out why the code breaks at line #285 please Help
      Error Message Response object error 'ASP 0156 : 80004005' Header Error /includes/utilities.asp, line 285 The HTTP headers are already...
    2. easy phone dating - meet any girl you find on this dating/sex line 4310
      Live Phone Dating - Call Now: 1-800-418-CHIC qcfegxbudfuwuqkqevdwhccfdpsyyvsbvfymcwz
    3. easy phone dating - meet any girl you find on this dating/sex line 5150
      Live Phone Dating - Call Now: 1-800-418-CHIC plnjskylpuvrkyxfbbdkcyidhjepcvmujmliorpb
    4. How to Find the Line # in a Given Paragraph
      Hello, Is there a way to find out the line number of the first line in a given paragraph? For example, I'm trying to find the line number of a...
    5. Director Mx basic : how to find line that contains specific word
      Hi, I try to find the command to put into the message window the line where is a specific word of a text. thank you, ...
  3. #2

    Default Re: Why can't it find the BeginTransaction line????

    I think you would get a better response if you posted to
    microsoft.public.dotnet.framework.adonet...



    [email]temple7502@rogers.com[/email]> wrote in message
    news:OkhWa.11484$4UE.3021@news01.bloor.is.net.cabl e.rogers.com...
    > Hi everyone,
    >
    > I am having a devil of a time with SqlTransactions, but I suspect the root
    > of the problem is actually pretty simple. I set up a transaction which
    > writes several employeeIDs to a datasource, in a loop. Then I deliberately
    > cause an error to see if the RollBack works. Only problem is when this
    > happens I get an error that says there is a RollBack without any
    > BeginTransaction. As you can see in the code, this is clearly not the
    case:
    >
    >
    >
    > Private Function insertEmployeeID()
    >
    >
    >
    > ' This function just gets the EmployeeID from all the enteries a listbox
    and
    > adds them to
    >
    > ' a Datasource.
    >
    >
    >
    > ' Loop through each driver, and add it to the table
    >
    > Dim intEmployeeMaxIndex As Integer
    >
    > Dim intEmployeeIndex As Integer
    >
    > Dim intEmployeeID As Integer
    >
    > Dim strInsertErrors As String
    >
    > Dim objTransaction As SqlTransaction
    >
    > Dim objCommand As New SqlCommand()
    >
    > Dim objConnection As SqlConnection
    >
    >
    >
    >
    >
    > intEmployee = employeeDriverList.Items.Count - 1 ' This is just a
    > listbox with the employees
    >
    > objConnection = New SqlConnection(Application("strConnection"))
    >
    >
    >
    > Try
    >
    >
    >
    > objConnection.Open()
    >
    > objTransaction = objConnection.BeginTransaction() ' Here is
    the
    > BeginTransaction, bright as brass
    >
    >
    >
    > ' *** Create the Command and set its properties
    >
    > objCommand.Connection = objConnection
    >
    >
    >
    > objCommand.CommandText = "sp_EmployeeInsert"
    >
    > objCommand.CommandType = CommandType.StoredProcedure
    >
    > objCommand.Transaction = objTransaction
    >
    >
    >
    > Dim objParam As SqlParameter
    >
    >
    >
    > For intEmployeeIndex = 0 To intEmployeeMaxIndex
    >
    > objCommand.Parameters.Clear() ' Clear out the previous
    > Parameters for new addition
    >
    >
    >
    > intEmployeeID =
    > CInt(employeeDriverList.Items(intEmployeeIndex).Va lue)
    >
    >
    >
    >
    >
    > ' *** Set the EmployeeID column
    >
    > objParam = objCommand.Parameters.Add("@EmployeeID",
    > SqlDbType.Int)
    >
    > objParam.Direction = ParameterDirection.Input
    >
    > objParam.Value = intEmployeeID
    >
    >
    >
    > If intEmployeeIndex = 1 Then
    >
    > ' *** Set a parameter that doesn't exist to cause an
    > error and
    >
    > ' *** test rollback
    >
    > objParam = objCommand.Parameters.Add("@blah",
    > SqlDbType.Int)
    >
    > objParam.Direction = ParameterDirection.Input
    >
    > objParam.Value = intEmployeeID
    >
    > End If
    >
    >
    >
    >
    >
    > objCommand.ExecuteNonQuery()
    >
    >
    >
    > If strInsertErrors <> "" Then
    >
    > Exit For
    >
    > End If
    >
    > Next intAuditGroupDriverIndex
    >
    >
    >
    >
    >
    > Catch e As Exception
    >
    > objTransaction.Rollback() ' Here is where the app complains
    > there is a rollback
    >
    > ' without a
    > beginTransaction
    >
    > strInsertErrors = "<div style='color:red'>* Error while
    > inserting Employee data" + e.Message + "<br/>"
    >
    > Return strInsertErrors
    >
    > End Try
    >
    >
    >
    > objTransaction.Commit()
    >
    > objConnection.Close()
    >
    >
    >
    > Return strInsertErrors
    >
    > End Function
    >
    >
    >
    >
    >
    > Please, tell me what I am missing here!!!
    >
    > Thanks
    >
    > Dano
    >
    >

    alien2_51 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139