3

I'm in the process of making live a .net system. I am using LINQ and MVC. I had to create the live database and hoped that this would run smoothly however it did not.

New SQL SERVER - Microsoft Windows NT 5.0 (2195) / 8.00.760

I created an administrator user who can add/edit/delete. Basically I receive the following error if I try to add (.InsertOnSubmit) or delete (.DeleteOnSubmit) any rows however not when I edit.

"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."

I've Googled this error and found people believe its to do with "MSDTC service" however this seems to be ticked on the service. I have logged into the database by SQL Server Management and this user can add/delete.

One Example:

Controller
if (_service.AddAccess(access)) return RedirectToAction("Access");

public Repository()
{
    _db = new DataClassDataContext(ConfigurationManager.ConnectionStrings["RegistrarsServices"].ConnectionString);
}

public void Save()
{
    _db.SubmitChanges();
}

public bool AddAccess(Access access)
{
    try
    {
        using (var scope = new TransactionScope())
        {
            _db.Accesses.InsertOnSubmit(access);
            Save();

            scope.Complete();
        }
        return true;
    }
    catch (Exception)
    {
        return false;
    }
}

*Please note this did work when using the development server. Microsoft Windows NT 5.2 (3790) / 10.0.1600.22

Controller

private readonly ServiceAdministration _service = new ServiceAdministration();

public ActionResult AddAccess()
{
    return View(new EmailViewModel());
}

[HttpPost]
public ActionResult AddAccess(EmailViewModel emailViewModel)
{
    if (emailViewModel.Button == "Back") return RedirectToAction("Access");

    if (!ModelState.IsValid) return View(emailViewModel);

    Access access = new Access();
    access.emailAddress = emailViewModel.emailAddress;

    if (_service.AddAccess(access)) return RedirectToAction("Access");

    emailViewModel.errorMessage = "An error has occurred whilst trying to grant access. Please try again later.";
    return View(emailViewModel);
}

Service

readonly Repository _repository = new Repository();

public bool AddAccess(Access access)
{
    return _repository.AddAccess(access);
}

Don't really know what I am missing.

Thanks in advance for any help.

Clare :-)

1 Answer 1

5

Do you have any idea why are you triggering distributed transactions? This is what you need to investigate. Usual culprit is multiple ADO.Net connection from a single TransactionScope. See ADO.NET and System.Transactions and ADO.NET and LINQ to SQL. Make sure you use a single connection (ie. LINQ2SQL context) in a transaction scope. You shouldn't have to use more than one per HTTP call anyway.

Sign up to request clarification or add additional context in comments.

8 Comments

No actually I don't. The controller doesn't hit another query extra before adding. Also unsure why it only does it on add/delete if its regarding distributed transactions would it not happen on the edit as well. Sorry if I sound stupid only really learning this now. Also it worked on the development server.
Are you sure there is no other outer TransactionScope in the code that calls your Repository? The inner scopes will then simple enroll into the outer scope and not really commit.
I am certain on the 'AddAccess' function. Please see updated question which includes code
Add Enlist=false to the connection string. If it tries to enlist in DTC it will raise C# exception at the place that triggers the enlistment.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.