DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Discuss "Connection must be valid and open to commit transaction" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old June 18th, 2008, 08:30 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 186
Thanks: 23
Thanked 4 Times in 4 Posts
Rep Power: 1
Shem is an unknown quantity at this point
Default Connection must be valid and open to commit transaction

the error msg:
Code:
 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Connection must be valid and open to commit transaction

Source Error:

Line 60:                 Return projectsId
Line 61:             Finally
Line 62:                 myTransactionScope.Dispose()
Line 63:                 'CType(myTransactionScope, IDisposable).Dispose()
Line 64:             End Try


Source File: c:\inetpub\wwwroot\keithdesign2\App_Code\global\BLL\ProjectsManager.vb    Line: 62

Stack Trace:

[InvalidOperationException: Connection must be valid and open to commit transaction]
   MySql.Data.MySqlClient.MySqlTransaction.Commit() +119
   MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment) +13
   System.Transactions.DurableEnlistmentCommitting.EnterState(InternalEnlistment enlistment) +257
   System.Transactions.DurableEnlistmentActive.ChangeStateCommitting(InternalEnlistment enlistment) +16
   System.Transactions.TransactionStateSPC.EnterState(InternalTransaction tx) +31
   System.Transactions.TransactionStateVolatilePhase1.EnterState(InternalTransaction tx) +277
   System.Transactions.TransactionStatePhase0.EnterState(InternalTransaction tx) +138
   System.Transactions.TransactionStateActive.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState) +47
   System.Transactions.CommittableTransaction.Commit() +210
   System.Transactions.TransactionScope.InternalDispose() +411
   System.Transactions.TransactionScope.Dispose() +2053
   Keith.ProjectsManager.Bll.ProjectsManager.Update(Projects myProjects) in c:\inetpub\wwwroot\keithdesign2\App_Code\global\BLL\ProjectsManager.vb:62

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +371
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
   System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
   System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method) +38
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +2539
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78
   System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1215
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +837
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +117
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +115
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +132
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +177
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
the relevant code: DAL
Code:
 Public Shared Function Update(ByVal myProjects As Projects) As Integer
            Dim result As Integer = 0
            ' Using
            Dim myConnection As MySqlConnection = New MySqlConnection(myConfig.myConnection)
            Try
                Dim myCommand As MySqlCommand = New MySqlCommand("sprocProjectsUpdateSingleItem", myConnection)
                myCommand.CommandType = CommandType.StoredProcedure
                'myCommand.Parameters.AddWithValue("?id", myProjects.Id)
                myCommand.Parameters.AddWithValue("?UserId", myProjects.UserId)
                myCommand.Parameters.AddWithValue("?TheDate", myProjects.TheDate)
                myCommand.Parameters.AddWithValue("?Name", myProjects.Name)
                myCommand.Parameters.AddWithValue("?Number", myProjects.Number)
                myCommand.Parameters.AddWithValue("?Description", myProjects.Description)
                'Dim returnValue As MySqlParameter
                'returnValue = myCommand.CreateParameter
                'returnValue.Direction = ParameterDirection.ReturnValue
                'myCommand.Parameters.Add(New MySqlParameter("?returnValue", returnValue))
                myConnection.Open()
                myCommand.ExecuteNonQuery()
                'result = Convert.ToInt32(returnValue.Value)
                myConnection.Close()
            Finally
                CType(myConnection, IDisposable).Dispose()
            End Try
            Return result
        End Function
the relevant code: BLL
Code:
<DataObjectMethod(DataObjectMethodType.Update, True)> _
        Public Shared Function Update(ByVal myProjects As Projects) As Integer
            ' Using
            Dim myTransactionScope As TransactionScope = New TransactionScope
            Try
                Dim projectsId As Integer = ProjectsDB.Update(myProjects)
                'For Each myZones As Zones In myProjects.Zones
                'myZones.ProjectId = projectsId
                'ZonesDB.Update(myZones)
                'Next
                myProjects.Id = projectsId
                myTransactionScope.Complete()
                Return projectsId
            Finally
                CType(myTransactionScope, IDisposable).Dispose()
            End Try
        End Function
any ideas guys
Shem
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old June 18th, 2008, 08:39 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 530
Thanks: 14
Thanked 38 Times in 37 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead is on a distinguished road

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

You're closing your connection within the Try block when you should be handling that in the Finally block.

Also, you should have a Catch block in which rolls back the transaction if there is a failure.
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
Reply With Quote
  #3 (permalink)  
Old June 18th, 2008, 08:49 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 186
Thanks: 23
Thanked 4 Times in 4 Posts
Rep Power: 1
Shem is an unknown quantity at this point
Default

how do i, "Catch block in which rolls back the transaction if there is a failure"?
will google it so long

Shem
Reply With Quote
  #4 (permalink)  
Old June 18th, 2008, 08:55 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 530
Thanks: 14
Thanked 38 Times in 37 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead is on a distinguished road

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Nevermind, I noticed you're using Transaction Scope instead of the MySqlTransaction class...

So you would want it to look something like this: TransactionScope Class (System.Transactions)
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick Links - Combo Open Forms AOG123 Microsoft Access 0 June 4th, 2008 08:46 AM
Open Web Page Jaykappy Microsoft Access 2 May 14th, 2008 06:32 PM
Wizard1 error The command 'MoveComplete' is not valid peebman2000 .Net Development 10 April 28th, 2008 02:52 PM
Is this valid ASP/ADO Code Wolffy ASP Development 4 April 14th, 2008 08:12 AM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 07:40 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

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