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

  • SEARCH
  • Home
  • 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 3235190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:28:42+00:00 2026-05-17T17:28:42+00:00

I started working on this already started project, and I’m having a really annoying

  • 0

I started working on this “already started” project, and I’m having a really annoying error when trying to execute some interactions with SQL Server 2008:

The server failed to resume the
transaction. Desc.:

One of these errors I get in this specific method call:

The aspx.cs Call:

busProcesso openProcess = new busProcesso(pProcessoId);
try
{
    if (openProcess.GetDocument() == null)
    {
        //Irrelevant code.
    }
}
catch{ //... }

The Business class (relevant part):

 public class busProcesso : IbusProcesso
 {
    public Processo vProcesso { get; set; }

    RENDBDataContext db;

    public busProcesso()
    {
        vProcesso = new Processo();
    }

    public busProcesso(decimal pProcessoId)
    {
        db = new RENDBDataContext();
        try
        {
             vProcesso = db.Processos.SingleOrDefault(x => x.Id == pProcessoId);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
    }

    public string GetDocument()
    {
        try
        {
            string document = null;
            foreach (Processo_has_Servico ps in ListaServicosProcesso())
            {
                if (ps.Servico.Document != null) //Get the error right at this line.
                {
                    document = ps.Servico.Document;
                }
            }
            return document ;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
    }

    public IQueryable<Processo_has_Servico> ListaServicosProcesso()
    {
        db = new RENDBDataContext();
        try
        {
            return from ps in db.Processo_has_Servicos
                   join s in db.Servicos on ps.Servico_Id equals s.Id
                   where ps.Processo_Id == vProcesso.Id
                   select ps;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
    }
}

As I said, the error occurs right at the line:

if (ps.Servico.Document != null) from the GetDocument() method.

Opening SQL Server Activity Monitor, I see there is a process for my database (.Net SqlClient Data Provider)

After some time/use (when I start to get the “server failed to resume the transaction” error), I go to the SQL Server Activity Monitor and there’s around 5 or 6 more identical processes that weren’t killed and (probably) should’ve been. When I manually kill them, the error stops for a while, until it starts again.

I’m not really good at working in OO and all, so I’m probably missing something, maybe some way to close one of these connections. Also, any help/tip about this structure will be welcome.

PS. The error doesn’t happen everytime. Sometimes it runs just perfectly. Then it starts to give the error. Then it stops. Sometimes it happens just once.. pretty weird.

  • 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-17T17:28:42+00:00Added an answer on May 17, 2026 at 5:28 pm

    The code in ListaServicosProcesso is creating the context db. Then it is returning an IQueryable.

    At this point no request has been sent to the database.

    Then there is a for each in the code. At this point EF says “I need to get the data from the database”. So it tries to get the data.

    But the context db is now out of scope, so it crashes, on the first line that tries to use the data.

    There are 2 ways to get around this:

    • return a list from ListaServicosProcesso, this will force the database call to execute
    • move the for each into ListaServicosProcesso

    Edit

    Pharabus is correct db is not out of scope. The problem is here:

     db = new RENDBDataContext();
    

    A new instance of the context is being created without the old one being disposed. Try Dispose of db at the end of ListaServicosProcesso. Even better place db in a using statement. But then the foreach must be moved inside the using statement.

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

Sidebar

Related Questions

I started working on CodeIgniter recently and I'm having some issues with the .htaccess
I just started working on a new project that already contains a .svn folder
I recently started working on a web project which was already in progress; the
I have started working on an MVC project and I came across some scenarios
I'm working on a project already started by several developers before me. One thing
Started working on a new application this week that is running the latest rails
I just discovered this component and started working with it. I understand that the
I recently started working with a client that had an index.html file with this
This is a very elementary I realize, I have recently started working with asp.net
I am currently working through this tutorial: Getting Started with jQuery For the two

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.