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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:52:58+00:00 2026-06-10T01:52:58+00:00

I am writing an application using EF 4.1 MVC3. I am trying to implement

  • 0

I am writing an application using EF 4.1 MVC3. I am trying to implement CRUD on it. The problem is that when i try to implement just first index page it gave me an error. I am using external database from central server. I am just trying a simple Registration form.
I have first model class RegModel.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Registration.Models
{
    public class Register
    {
        public int Id { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Email { get; set; }
        public string Address { get; set; }
    }
}

Then a RegModelContext.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Registration.Models
{
    public class Register
    {
        public int Id { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Email { get; set; }
        public string Address { get; set; }
    }
}

My controller name is RegController.cs (I am just trying to implement Index first.) in controller. When i am executing my application it gave me error on return View(db.Registrant.ToString()); that
“entitycommandexecutionexception was unhandled”
“An error occurred while executing the command definition. See the inner exception for details.”

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Registration.Models;
using System.Configuration;


namespace Registration.Controllers
{
    public class RegController : Controller
    {
        //
        // GET: /Reg/
        private string CmdStr = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;      
        public ActionResult Index()
        {
            using (var db = new RegModelContext(CmdStr))
            {
                return View(db.Registrant.ToString());
            }

        }

    }
}

Then by using Index I create view for index (Index.cshtml):

@model IEnumerable<Registration.Models.Register>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
</head>
<body>
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table>
        <tr>
            <th></th>
            <th>
                UserName
            </th>
            <th>
                Password
            </th>
            <th>
                Email
            </th>
            <th>
                Address
            </th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
                @Html.ActionLink("Details", "Details", new { id=item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.Id })
            </td>
            <td>
                @item.UserName
            </td>
            <td>
                @item.Password
            </td>
            <td>
                @item.Email
            </td>
            <td>
                @item.Address
            </td>
        </tr>
    }

    </table>
</body>
</html>

I am using this web.config file

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="MyConn" connectionString="Data Source=WIN-A32JMN2HC3A\SAIGMAMSSQL;Initial Catalog=Registration;User Id=SAIGMA110;Password=12345;"/>    
  </connectionStrings>
</configuration>
  • 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-06-10T01:53:01+00:00Added an answer on June 10, 2026 at 1:53 am

    The problem is with this code:

    string CmdStr = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString; 
    using (var db = new RegModelContext(CmdStr))
    {
        return View(db.Registrant.ToString());
    }
    

    First, you don’t need to specify the connection string explicitly. By convention the Entity Framework will look for a matching connection string in your web.config file. Just make sure the name of the connection string matches the name of your DbContext.

    Second, you are accessing a collection of Register objects in your database trough db.Registrant. Calling ToString() on it doesn’t make any sense.

    Your view expects a list of Registration.Models.Register instead of a string. Change your code to this:

    using (var db = new RegModelContext())
    {
        return View(db.Registrant.ToList());
    }
    

    Be aware that this is returning all Register items in your database. That could be a whole lot data. Maybe you want to implement paging or another type of filtering to make sure that everything works as expected.

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

Sidebar

Related Questions

I'm writing an ASP.net MVC3 application using Entity Framework Code First and SqlCe4. I
I am writing an application using Cairo in C that does the following: Load
I'm writing an application using DDD techniques. This is my first attempt at a
I'm currently writing an application using Vala that requires me to send data over
I'm writing an application using WPF, and I need to make something that looks
I have problem concerning python packages and testing. I'm writing an application using wx
I'm writing an application using the public Tumblr API, just for fun. I have
I am writing an application using Symfony. I have some reusable components that I
I am writing an MVC 3 application and I am trying to implement my
im writing an application using Visual Studio 2010 Express Edition. I have a problem

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.