Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:16:01+00:00 2026-05-26T20:16:01+00:00

I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions

  • 0

I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions as follows:

using (var transaction = new TransactionScope())
{
    // Database action 1

    // Database action 2

    context.SaveChanges();

    Logger.Info("Record X updated");

    transaction.Complete();
}

I get no errors, but no data is written to the database. However, the log file target (there just for testing purposes) works fine. Here is my nLog (I’m using v2) config:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        throwExceptions="true"
        internalLogToConsole="true"
        internalLogToConsoleError="true" >

  <targets>
      <target name="logfile" xsi:type="File" fileName="${basedir}app_data\file.txt"  />

     <target xsi:type="Database" name="database">
        <commandText>INSERT INTO [LogEntries] (TimeStamp, Message, Level, Logger) VALUES(GETDATE(), @msg, @level, @logger)</commandText>
        <parameter name="@msg" layout="${message}" />
        <parameter name="@level" layout="${level}" />
        <parameter name="@logger" layout="${logger}" />
        <dbProvider>System.Data.SqlServerCe.4.0</dbProvider>
        <connectionString>Data Source=${basedir}app_data\Logger.sdf</connectionString>
     </target>
  </targets>

  <rules>
      <logger name="*" minlevel="Trace" writeTo="logfile" />
      <logger name="*" minlevel="Trace" writeTo="database" />
  </rules>
</nlog>

If I move the Logger line outside of the transactionscope it works fine. So I think it’s something to do with this. I’m using SQL Server 2008 r2 for my main database and SQL Compact 4 for my logging database. Also, I’ve tried adding useTranscations=”true”.

Any ideas what I’m doing wrong?

Thanks

Alan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:16:02+00:00Added an answer on May 26, 2026 at 8:16 pm

    You are trying to have the transaction span two different servers, which is a distributed transaction. Unfortunately, SQLCE does not support distributed transactions (from the documentation):

    Distributed transactions are not supported in SQL Server Compact. Therefore, a local transaction will not be automatically promoted to a fully distributable transaction.

    I am curious why you don’t log to the SQL 2008 R2 database, but if you must log to SQLCE, I think you’ll have to track whether the transaction is committed and then determine whether to call NLog after the the TransactionScope block completes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC 2.0 application using Entity Framework. All my views use
I have a ASP.NET MVC 3 application, using Entity Framework 4 to handle Data
I have an application developed in ASP.NET MVC using Entity Framework / Sql Server
I am using the asp.net mvc with the Entity Framework. I have a list
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
General Info: ASP.NET MVC app using ADO.NET Entity Framework SQL Server 2005 I have
I'm using the Entity Framework 4.1 and ASP.Net MVC 3 for my application. MVC
I've built an MVC 2 application (ASP.net 3.5) using Entity Framework, and am doing
I have an ASP.NET MVC application using Authorization Attributes on Controllers and Actions. This
I have a ASP.NET MVC application using NHibernate and the application runs fine when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.