Hi,
I have Captaris 6.0 installed. After calling the instance of the workflow model in the code, i used to set the responsible property of each process.
just after that i used to commit the process and dispose the Engine instance.
It used to work absolutely fine earlier, but these days i get an error which says -
A TransactionScope must be disposed on the same thread that it was created.%0ASource : System.Transactions%0ATargetSite : Void Dispose()%0AStackTrace : %0AServer stack trace: %0A at System.Transactions.TransactionScope.Dispose()%0A at Teamplate.BLL.BProcess.Rollback()%0A at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)%0A at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)%0A at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)%0A%0AException rethrown at [0]: %0A at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)%0A at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)%0A at Teamplate.BLL.BProcess.Rollback()%0A
Can somebody please tell me how can i get rid of this error, as this is already in the live environment.
Here is the entire code
Dim myProcess As BProcess = New BProcess
Dim mySession As BSession = New BSession()
Dim myUser As Teamplate.BLL.BUser = New BUser
Dim intFolderID As Integer, intModelID As Integer, intTaskID As Integer, intResponsibleID As Integer
Dim strResponsibleName As String = "", strResponsibleEmail As String = "", boolIsLastTask As Boolean
Dim strResponsibleType As String = "", strResponsibleRelation As String = "", strResponsibleNetworkName As String = ""
Dim intRelationUserID As Integer
'------------Connect To the remote Server--------
Dim cwEngine As New WorkflowEngineWs.WorkflowEngine()
cwEngine.PreAuthenticate =
True
cwEngine.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials()
strSessionToken = cwEngine.Connect(
"", "", "")
intUserID = cwEngine.GetUserId(strSessionToken)
intModelID = Int32.Parse(ConfigurationManager.AppSettings(
"ModelID").ToString())
strSQL =
"Exec GetModelFolder " & intModelID
dtWorkflow = sqlHelper.ExecuteDataTable(ConnectionString, strSQL, CommandType.Text, ,
False)
If dtWorkflow.Rows.Count > 0 Then
intFolderID = dtWorkflow.Rows(0)(
"FolderID").ToString
End If
myUser.SetSessionToken(strSessionToken)
myProcess.SetSessionToken(strSessionToken)
'Dim pid As Integer = cwEngine.CreateProcess(strSessionToken, "", intFolderID, intUserID, intModelID, wasSuccessful, wserror)
Dim pid As Integer = myProcess.Add("", intFolderID, intUserID, intModelID)
If Not wasSuccessful Then
lblMessage.Text = wserror.ToString
cwEngine.Dispose()
Exit Sub
End If
dtWorkflow =
Nothing
strSQL =
"Exec GetCaptarisUserID null, '" & txtuser.text & "'"
dtWorkflow = sqlHelper.ExecuteDataTable(ConnectionString, strSQL, CommandType.Text, ,
False)
If dtWorkflow.Rows.Count > 0 Then
intRelationUserID = dtWorkflow.Rows(0)(
"UserID")
End If
dtWorkflow =
Nothing
strSQL =
"Exec GetResponsible " & intModelID & ", " & intRelationUserID
dtWorkflow = sqlHelper.ExecuteDataTable(ConnectionString, strSQL, CommandType.Text, ,
False)
If dtWorkflow.Rows.Count > 0 Then
intTaskID = dtWorkflow.Rows(0)(
"TaskID")
intResponsibleID = dtWorkflow.Rows(0)(
"ResponsibleID")
strResponsibleName = dtWorkflow.Rows(0)(
"DisplayName")
strResponsibleEmail = dtWorkflow.Rows(0)(
"Email")
boolIsLastTask = dtWorkflow.Rows(0)(
"IsLastTask")
strResponsibleType = dtWorkflow.Rows(0)(
"ResponsibleType").ToString
strResponsibleRelation = dtWorkflow.Rows(0)(
"ResponsibleRelation").ToString
strResponsibleNetworkName = dtWorkflow.Rows(0)(
"NetworkName").ToString
End If
If strResponsibleType = "Group" Then
dtWorkflow =
Nothing
strSQL =
"Exec GetUserRelations " & intResponsibleID & ", '" & strResponsibleRelation & "', " & intModelID & ", " & intTaskID
dtWorkflow = sqlHelper.ExecuteDataTable(ConnectionString, strSQL, CommandType.Text, ,
False)
If dtWorkflow.Rows.Count > 0 Then
intResponsibleID = dtWorkflow.Rows(0)(
"UserID")
strResponsibleName = dtWorkflow.Rows(0)(
"DisplayName").ToString
strResponsibleEmail = dtWorkflow.Rows(0)(
"Email").ToString
End If
End If
'-----------Set TaskResponsibleId
myProcess.BeginTransaction()
myProcess.Load(pid)
myProcess.SetTaskResponsibleID(intTaskID, intResponsibleID)
myProcess.SetTextValue(
"xmlKey", "xmlKey", strPKey)
myProcess.SetTextValue(
"xmlApproval", "xmlApproval/IsLastTask", IIf(boolIsLastTask, "1", "0"))
myProcess.SetTextValue(
"xmlApproval", "xmlApproval/IsHeadApprovalRequired", "False")
If strResponsibleType.ToLower = "Relation".ToLower And strResponsibleRelation.ToLower = "Managed By".ToLower Then
myProcess.SetTextValue(
"xmlApproval", "xmlApproval/TaskIdWithRelationManagedBy", intTaskID)
myProcess.SetTextValue(
"xmlApproval", "xmlApproval/ResponsibleManagedByUserNetworkName", strResponsibleNetworkName)
myProcess.SetTextValue(
"xmlApproval", "xmlApproval/ResponsibleManagedByUserID", intResponsibleID)
End If
dtWorkflow =
Nothing
strSQL = "Exec GetAllResponsible_Girish " & intModelID & ", " & intRelationUserID & ",'" & strApprovalTypeID & "'"
dtWorkflow = sqlHelper.ExecuteDataTable(ucPageHeader.WorkflowConnectionString, strSQL, CommandType.Text, , False)
For intRowCount As Integer = 0 To dtWorkflow.Rows.Count - 1
If dtWorkflow.Rows(intRowCount)("TaskID") <> intTaskID Then
myProcess.SetTaskResponsibleID(dtWorkflow.Rows(intRowCount)("TaskID"), dtWorkflow.Rows(intRowCount)("UserID"))
End If
Next
myProcess.Commit()
cwEngine.Dispose()