Thanks for your response, I already create the database, and then the table appear in the Server Explorer, with table name "Accommodation" but in SQL Server Management Studio, I see the table name is "dbo.Accommodations" I don't know whether the problem is about this pluralization or not.. What do you think?
On Sep 9, 9:38 pm, "Tyler Sommer" <[email protected]> wrote: > That is a SqlException-- your SQL query cannot find the table > 'dbo.Accomodations'.. Have you ensured this table exists? > > -----Original Message----- > From: [email protected] > > [mailto:[email protected]] On Behalf Of RC's > Sent: Wednesday, September 08, 2010 12:57 PM > To: DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web > Services,.NET Remoting > Subject: [DotNetDevelopment] Problem with ASP.NET MVC 2 - List records from > table > > Hi everyone, > I'm creating a website based on ASP.NET MVC 2 and SQL Server 2008 R2 Express > for the database. > After creating the table in database, I want to list all records in that > table. For that, I use "scaffold'ing in ASP.NET to automatically generate > the view file. But I encountered an error when loading that page. > The error message was: > > [CODE] > Server Error in '/' Application. > Invalid object name 'dbo.Accommodations'. > Description: An unhandled exception occurred during the execution of the > current web request. Please review the stack trace for more information > about the error and where it originated in the code. > > Exception Details: System.Data.SqlClient.SqlException: Invalid object name > 'dbo.Accommodations'. > > Source Error: > > Line 41: </tr> > Line 42: > Line 43: <% foreach (var item in Model) { %> > Line 44: > Line 45: <tr> > > Source File: d:\MyProject\Views\Accommodation\Index.aspx Line: 43 > > Stack Trace: > > [SqlException (0x80131904): Invalid object name 'dbo.Accommodations'.] > System.Data.SqlClient.SqlConnection.OnError(SqlException exception, > Boolean breakConnection) +2030802 > System.Data.SqlClient.SqlInternalConnection.OnError(SqlException > exception, Boolean breakConnection) +5009584 > System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 > System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand > cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet > bulkCopyHandler, TdsParserStateObject > stateObj) +2275 > System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33 > System.Data.SqlClient.SqlDataReader.get_MetaData() +86 > System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader > ds, RunBehavior runBehavior, String resetOptionsString) +311 > > System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean > async) +987 > System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, > DbAsyncResult result) +162 > System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior > cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String > method) +32 > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior > behavior, String method) +141 > > System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior > behavior) +12 > System.Data.Common.DbCommand.ExecuteReader(CommandBehavior > behavior) +10 > > System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(Entity > Command > entityCommand, CommandBehavior behavior) +443 > > [EntityCommandExecutionException: An error occurred while executing the > command definition. See the inner exception for details.] > > System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(Entity > Command > entityCommand, CommandBehavior behavior) +479 > > System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext > context, ObjectParameterCollection parameterValues) +736 > System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 > forMergeOption) +149 > > System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>. > GetEnumerator() > +44 > ASP.views_accommodation_index_aspx.__RenderContent2(HtmlTextWriter > __w, Control parameterContainer) in d:\MyProject\Views\Accommodation > \Index.aspx:43 > System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, > ICollection children) +109 > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 > System.Web.UI.Control.Render(HtmlTextWriter writer) +10 > System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, > ControlAdapter adapter) +27 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter > adapter) +100 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 > ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, > Control parameterContainer) in d:\MyProject\Views\Shared\Site.Master: > 26 > System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, > ICollection children) +109 > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 > System.Web.UI.Control.Render(HtmlTextWriter writer) +10 > System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, > ControlAdapter adapter) +27 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter > adapter) +100 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 > System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, > ICollection children) +208 > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 > System.Web.UI.Page.Render(HtmlTextWriter writer) +29 > System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56 > System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, > ControlAdapter adapter) +27 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter > adapter) +100 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 > System.Web.UI.Page.ProcessRequestMain(Boolean > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) > +3060 > > [/CODE] > > and the syntax for creating table is like this : > [CODE] > -- Creating table 'Accommodations' > CREATE TABLE [dbo].[Accommodations] ( > [ID] int IDENTITY(1,1) NOT NULL, > [Name] varchar(63) NOT NULL, > [Star] smallint NOT NULL, > [Price] decimal(10,2) NOT NULL, > [Address] varchar(63) NOT NULL, > [City] varchar(63) NULL, > [Province] varchar(63) NULL, > [Phone] varchar(31) NULL, > [Description] varchar(max) NULL > ); > GO > [/CODE]
