Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. InvalidOperationExpression was unhandled by user code(Enterprise Library)

InvalidOperationExpression was unhandled by user code(Enterprise Library)

Scheduled Pinned Locked Moved Web Development
databasehelpsharepoint
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EliteBrain
    wrote on last edited by
    #1

    Public Function GetMaxSerialNumber(ByVal docType) As Int32

          Dim db As Database = DatabaseFactory.CreateDatabase("igrwebConnectionString")
    
          Dim sqlCommand As String = SP\_UPDATE\_DOCUMENTDETAILS
          Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand)
          db.AddInParameter(dbCommand, "@operationType", DbType.String, "R")
          db.AddInParameter(dbCommand, "@cType", DbType.Int64, docType)
    
          Dim SrNo As Integer = db.ExecuteScalar(dbCommand)
          Return SrNo + 1
    
      End Function
    

    The above code is giving an exception at db.ExecuteScalar(dbCommand) Error is

    ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

    Please Help as i am new to enterprise library

    J 1 Reply Last reply
    0
    • E EliteBrain

      Public Function GetMaxSerialNumber(ByVal docType) As Int32

            Dim db As Database = DatabaseFactory.CreateDatabase("igrwebConnectionString")
      
            Dim sqlCommand As String = SP\_UPDATE\_DOCUMENTDETAILS
            Dim dbCommand As DbCommand = db.GetStoredProcCommand(sqlCommand)
            db.AddInParameter(dbCommand, "@operationType", DbType.String, "R")
            db.AddInParameter(dbCommand, "@cType", DbType.Int64, docType)
      
            Dim SrNo As Integer = db.ExecuteScalar(dbCommand)
            Return SrNo + 1
      
        End Function
      

      The above code is giving an exception at db.ExecuteScalar(dbCommand) Error is

      ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

      Please Help as i am new to enterprise library

      J Offline
      J Offline
      JV9999
      wrote on last edited by
      #2

      As the exception says you need to instantiate a transaction in your code (which you aren't doing at this moment). That will fix your issue.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups