Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transaction problem
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01145499
Message ID:
01145841
Views:
20
Hi Kevin,
Here is the code.
        protected override void HookPostSave(DataTable dt)
        {

            foreach (DataRow dr in dt.Rows)
            {
                // audit trail
                this.AuditTrail(dr);
            }
        }

        private void AuditTrail(DataRow dr)
        {
            this.AuditTrail(dr, false);
        }
        private void AuditTrail(DataRow dr, Boolean IsDeleted)
        {
            try
            {
                IDbDataParameter param1 = this.CreateParameter("@ID", System.Guid.NewGuid());
                IDbDataParameter param2 = this.CreateParameter("@TableName", dr.Table.TableName);
                IDbDataParameter param3 = this.CreateParameter("@UserID", this.UserID);
                IDbDataParameter param4 = this.CreateParameter("@AuditType", this.IsNew == true ? "INSERT" : IsDeleted == true ? "DELETED" : "UPDATE");
                IDbDataParameter param6 = this.CreateParameter("@AfterData", "Data Saved");
                IDbDataParameter param7 = this.CreateParameter("@LastUpdatedOn", Convert.ToInt64(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0') + DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0')));
                IDbDataParameter param8 = this.CreateParameter("@PrimaryKey", dr["ID"]);
                string fielddata = "";
                foreach (DataColumn col in dr.Table.Columns)
                {
                    fielddata += col.ColumnName.ToString() + "=" + dr[col].ToString() + ";";
                }

                IDbDataParameter param5 = this.CreateParameter("@BeforeData", fielddata);
                string lcsql = "INSERT INTO AuditTrail([ID],[TableName],[UserID],[AuditType]," +
                               "[BeforeData],[AfterData],[LastUpdatedOn],[PrimaryKey]) VALUES (" +
                                "@ID,@TableName,@UserID,@AuditType,@BeforeData,@AfterData,@LastUpdatedOn,@PrimaryKey)";
                
                this.ExecNonQuery(lcsql, param1, param2, param3, param4, param5, param6, param7, param8);
               

            }
            catch
            { }

        }
>Fred,
>
>>In my AbusinessObject I have a hook for post save and I have AutoUseTransactions = true
>>
>>protected override void HookPostSave(DataTable dt)
>>{
>>// Insert a record into my audit trail table using ExecNonQuery.
>>}
>>
>>I get this Exception:The transaction is either not associated with the current connection or has been completed.
>
>Can you post the actual code you have in your HookPostSave() method?
>
>Best Regards,
Fred Besterwitch, MCP

The harder you work. The luckier you get.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform