Click here to Skip to main content
15,672,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I have encounter this exception when i had to change the field name from the table on my database.
  Message=An error occurred while executing the command definition. See the inner exception for details.
  Source=<Cannot evaluate the exception source>
<Cannot evaluate the exception stack trace>

Inner Exception 1:
SqlException: Invalid object name 'dbo.TrainingRegForms'.

What I have tried:

// Model
<pre>public class TrainingRegForm
        public int? Id { get; set; }
        public string Title { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Position { get; set; }
        public string Company { get; set; }

        public string StreetAddress { get; set; }

        public string StreetAddressLine { get; set; }

        public string City { get; set; }
        public string StateProvince { get; set; }

        public int ZipCode { get; set; }

        public string Country { get; set; }

        public string Email { get; set; }

        public string CellNumber { get; set; }
        public string DietaryRequirement { get; set; }

// Controller
public ActionResult Download_XMLReport()
            eNtsaRegistration context = new eNtsaRegistration();

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Path.Combine(Server.MapPath("~/Reports"), "AcademyReports.rpt"));
            rpt.SetDataSource(context.TrainingRegs.Select(c => new
                Id = c.Id,
                Title = c.Title

            Response.Buffer = false;

            rpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
            rpt.PrintOptions.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(5, 5, 5, 5));
            rpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA5;

            Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            stream.Seek(0, SeekOrigin.Begin);

            return File(stream, "application/xml", "eNtsaReportTrainingForm.xml");
Updated 21-Jul-20 3:37am

1 solution

It could be one of the following:

1. no such table (dbo.TrainingRegForms)
2. table is there, but there is no dbo scheme (it might be in XYZ.TrainingRegForms instead of dbo.TrainingRegForms)
3. the db is case-sensitive, and the thus the table is dbo.TRAININGREFFORMS

Please check your database setup and the table in it that you are trying to access.
Share this answer
gcogco10 21-Jul-20 10:38am    
Sandeep, i accidentically deleted from the database itself. Although the DbContext points to it. On SQLServer, the table is deleted, tried to do "update-database" fails as well. What can i do?
Sandeep Mewara 21-Jul-20 11:19am    
You would need to use CREATE TABLE command to create it.
gcogco10 21-Jul-20 11:21am    
on the sql server itself or console from visual studio?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900