I get this error “ExecuteReader 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” - I started a transaction and gets this error when I do a select - code snippet looks like this:
using (var db = DbConnectionFactory.Open())
{
var tday = DateTime.Now;
var trans = db.BeginTransaction();
try
{
UserSubscription subscription = userSubscription;
List<UserSubscription> userSubscriptions = db.Select<UserSubscription>(s => s.SubscriberId == subscription.SubscriberId && s.SubscriptionPackageId == subscription.SubscriptionPackageId);
if (userSubscriptions.Any())
…
Any clue?
You need to use OpenTransaction, e.g:
https://github.com/ServiceStack/ServiceStack.OrmLite#transaction-support
Binu Thayamkery:
Whats the difference between begintransaction and opentransaction ? I swear begintransaction used to work
Binu Thayamkery:
Thanks anyways…all good now.
BeginTransaction is ADO.NET’s API, OpenTransaction is OrmLite’s managed API for opening a transaction, one of the differences is that it attaches it to the DB commands created within a transaction, preventing this error
Binu Thayamkery:
Thanks Demis for answering my naive question - I should have just looked up the code - It was easier to just ask you