This project is read-only.

Just tried to publish a simple Products widget. Got this SQL Error:

Topics: Customizing Orchard, Troubleshooting
Nov 15, 2011 at 6:46 PM

Invalid object name 'Pryor_Products_ProductRecord'.

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 'Pryor_Products_ProductRecord'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[SqlException (0x80131904): Invalid object name 'Pryor_Products_ProductRecord'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2073502
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064460
   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.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215
   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.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
   NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) +297
   NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) +17
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) +496

[GenericADOException: could not insert: [Pryor.Products.Models.ProductRecord#42][SQL: INSERT INTO Pryor_Products_ProductRecord (Product, Price, Type, Format, Id) VALUES (?, ?, ?, ?, ?)]]
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) +728
   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) +166
   NHibernate.Action.EntityInsertAction.Execute() +180
   NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +117
   NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +92
   NHibernate.Engine.ActionQueue.ExecuteActions() +16
   NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +168
   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +56
   NHibernate.Impl.SessionImpl.Flush() +292
   NHibernate.Transaction.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) +395

[TransactionAbortedException: The transaction has aborted.]
   System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx) +11
   System.Transactions.CommittableTransaction.Commit() +239
   System.Transactions.TransactionScope.InternalDispose() +402
   System.Transactions.TransactionScope.Dispose() +1450
   Orchard.Data.TransactionManager.System.IDisposable.Dispose() in d:\Builds\OrchardFull\src\Orchard\Data\TransactionManager.cs:47
   Autofac.Core.Disposer.Dispose(Boolean disposing) +79
   Autofac.Util.Disposable.Dispose() +46
   Autofac.Core.Lifetime.LifetimeScope.Dispose(Boolean disposing) +21
   Autofac.Util.Disposable.Dispose() +46
   Orchard.Environment.<>c__DisplayClass2.<.ctor>b__0() in d:\Builds\OrchardFull\src\Orchard\Environment\WorkContextAccessor.cs:75
   Orchard.Environment.HttpContextScopeImplementation.System.IDisposable.Dispose() in d:\Builds\OrchardFull\src\Orchard\Environment\WorkContextAccessor.cs:80
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in d:\Builds\OrchardFull\src\Orchard\Mvc\Routes\ShellRoute.cs:151
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Nov 15, 2011 at 6:52 PM

Just checked by database and that table never got created! Followed the steps like I have 20 times before. Data Migration did not create the table when I enabled the Module/Widget.

Nov 15, 2011 at 7:19 PM

What this can mean is that your migration has already run and so the database has the version counter at '2' (therefore it'll never run your version '1' migration).

You can experimentally copy your Create method to an UpdateFrom1() and try upgrading the module. You can also alter the counter in the database (but I can't remember the table without some digging).

Nov 15, 2011 at 8:22 PM

Ok. Ive tried a few different things. NHibernate is still not adding my table to the database. I've changed Create() return 1 to Create() return 2 and UpdateFrom1 return 2. I've also done this for 3 and 4. I also disabled the Module. Pulled the Module folder out of the root directory. Created and new module using codegen, added all my files into the new module. Enabled it. ProductRecord table is still not being created.



Nov 15, 2011 at 8:26 PM

Did you try putting breakpoints in these migrations? What's in your Orchard_Framework_DataMigrationRecord table?

Nov 15, 2011 at 8:27 PM
Edited Nov 15, 2011 at 8:29 PM

I found the data migration record in the database. Should I delete the row pertaining to my module or change the version to 0 or 1??



Nov 15, 2011 at 8:36 PM

If you need it to go through Create again, you can zap the row.