NorCode
NorCode

Reputation: 689

How to create Transaction Commit and Rollback in Webmatrix.Data.Database

I am writing a code for my webmatrix project where transaction commit and rollback is applied. I am Using mysql 5.1 and innodb database engine for transaction support.

I use

db.Connection.BeginTransaction();
                try
                {
                    db.Execute("Insert into tmp_upload_img(`path`,`type`) values(@0)", FullPath,"Fullimage");
                    db.Execute("Insert into tmp_upload_img(`path`,`type`) values(@0)", ThumbPath, "Thumbimage");
                    db.Execute("Insert into tmp_upload_img(`path`,`type`) values(@0)", SmallPath, "Smallimage");
                    db.Connection.BeginTransaction().Commit();
                }
                catch
                {
                    db.Connection.BeginTransaction().Rollback();
                }

But I Not achieve transaction support for webmatrix project.

I know this can achieve with mysql.data.mysqlclient, but i want to know it is possible with webmatrix.data class ?.

Upvotes: 3

Views: 1106

Answers (1)

Mike Brind
Mike Brind

Reputation: 30110

The Database class in WebMatrix.Data doesn't offer anything in terms of support for transactions. It was designed to make it easy for beginners to get on board with ASP.NET. If you want to use transactions in a Web Pages site, you can use plain ADO.NET code for your data access, or you can use something like the Entity Framework which has transaction support built in.

Upvotes: 2

Related Questions