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 1102057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:07:30+00:00 2026-05-17T01:07:30+00:00

I am working in ASP.Net MVC 1.0 and SQL Server 2000 using Entity Framework.

  • 0

I am working in ASP.Net MVC 1.0 and SQL Server 2000 using Entity Framework.
My faulty controller code is given below:

            int checkUser = id ?? 0;
            string userNameFromNew, userNameToNew;

            if (checkUser == 1)
            {
                userNameFromNew = "U" + Request.Form["usernameFrom"];
                userNameToNew = "U" + Request.Form["usernameTo"];
            }
            else
            {
                userNameFromNew = "C" + Request.Form["usernameFrom"];
                userNameToNew = "C" + Request.Form["usernameTo"];
            }

            var rMatrix = from Datas in repository.GetTotalRightData() 
                          where Datas.UserName == userNameFromNew.Trim()
                          select Datas;

            Right_Matrix RM = new Right_Matrix();


            foreach(var Data in rMatrix)
            {
                RM.Column_Id = Data.Column_Id;
                RM.ProMonSys_Right = Data.ProMonSys_Right;
                RM.UserName = userNameToNew;
                UpdateModel(RM);
                this.repository.AddRightTransfer(RM);
            }

            return RedirectToAction("RightTransfer");

My faulty model code is given below:

            public void AddRightTransfer(Right_Matrix RM)
            {
                context.AddObject("Right_Matrix", RM);
                context.SaveChanges();
            }

My code shows error once it is in the model code stating the DataReader is already open and I need to close it first.

Please suggest a workaround.

  • 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-17T01:07:30+00:00Added an answer on May 17, 2026 at 1:07 am

    Try moving the AddRightTransfer loop out of the LINQ foreach, and into a separate one. I think LINQ is executing the first add before the database result set is closed. By moving the call to AddRightTransfer into a second foreach, you should avoid the problem, if that’s what is happening.

    Here’s an example:

    List<Right_Matrix> matrixes = new List<Right_Matrix>();
    
    foreach (var Data in rMatrix)
    {
        Right_Matrix rm = new Right_Matrix();
        rm.Column_Id = Data.Column_Id;
        rm.ProMonSys_Right = Data.ProMonSys_Right;
        rm.UserName = userNameToNew;
        UpdateModel(rm);
        matrixes.Add(rm);
    }
    
    foreach (var rm in matrixes)
    {
        this.repository.AddRightTransfer(rm);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The setup: (using Asp.Net MVC 2 RC, Entity Framework, SQL Server, VS2008) My buddy
I'm working on an recipe module (ASP.NET MVC, entity framework, sql server), and one
i've started working with ASP.NET MVC and using Entity Framework, concretely with SQLite db,
I am working on a sql server 2008 DB and asp.net mvc web E-commerce
I'm working in ASP.NET MVC 1.0 using MvcContrib FluentHtml version 1.0. The following code
I am working on an ASP.NET MVC application using SQL Dapper for retrieval and
I´m working with ASP.NET MVC and went through some code and the syntax below
I'm working with an ASP.NET MVC 2 project using a classic ASP.NET WebForm wired
Context: ASP.NET MVC 2.0, Linq-to-Sql, .Net 3.5, IIS7, MS SQL 2008 I'm working on
I've created a locally attached SQL Server 2008 Express for an ASP.NET MVC application

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.