Deployed Website - Module Enable Error

Topics: Administration, Troubleshooting
Mar 4, 2015 at 10:28 PM
Hi,

I have created a website on my dev machine and deployed the site to a shared hosting provider on a virtual directory.

The website uses Sql Server Express (not CE) and after setting the ConnectionString in Settings.txt the first deployment worked well. Also I used web deploy and used "Exclude contents of App_Data". Thus, when code was deployed, I imported initial database from dev machine to live (shared hosting) website.

Now, to check how deployment works, I added the MapPart to my dev machine and added that to a sample Person content type and it displays properly.

Now when I deploy the website (with new module) to shared hosting, the web site works properly. If I sign in to dashboard, I get a compiler error, but after refresh, the dashboard loads up.

When I now enable my MapPart module, I get an "Information bar" saying module was enabled, but the "Enable" next to module stays same in Modules menu. As in, It does not get enabled and change to "Disable".

The error in log is below:
2015-03-04 14:13:59,186 [150] Orchard.Data.SessionLocator - Default - Error while disposing the transaction.
 http://mywebsite.com/carshop/Admin/Modules/Features
NHibernate.Exceptions.GenericADOException: could not insert: [Orchard.Core.Settings.Descriptor.Records.ShellFeatureRecord][SQL: INSERT INTO Settings_ShellFeatureRecord (Name, ShellDescriptorRecord_id) VALUES (?, ?); select SCOPE_IDENTITY()] ---> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'Id', table 'carshop.dbo.Settings_ShellFeatureRecord'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I know that the deployment method I've used is skeptical. But does this have to do anything with it? or how do I proceed?

Any suggestions are welcome. Thanks.
Mar 5, 2015 at 9:03 PM
Hi,

After the above post, I tried the following:
  1. I am working with full Orchard Source (1.8.1)
  2. Completed the steps suggested by https://orchard.codeplex.com/discussions/471305 which showed how to build Precomplied.
    This process created a build folder and inside that, it creates 3 folders (Compile, Precompiled, Stage).
    As suggested, I uploaded the contents of "Precompiled" folder to the live site.
When I began step 1, the website had a MapPart. For the first deployment, I migrated my Sql Server Express database to shared host using "Import Data" from SSMS.

Now the idea was to add a ComputerPart which would be tied to a new ContentType created from Admin page called "Computer".
  1. I added the computer part in my dev machine and everything worked.
  2. Deployed by creating a new "build precompiled" and uploaded it to production. Now the problem is, the MapPart which was "Import Data" gotten, was present as expected. I do see the module --> "ComputerPart" which can be enabled. Now when I "Enable" the part, it says on information bar that the part was enabled, but no change happens.
The Latest log is below:
2015-03-05 12:49:27,155 [128] Orchard.Data.SessionLocator - Default - Error while disposing the transaction.
 http://mysoremane.com/carshop/Admin/Modules/Features
NHibernate.Exceptions.GenericADOException: could not insert: [Orchard.Core.Settings.Descriptor.Records.ShellFeatureRecord][SQL: INSERT INTO Settings_ShellFeatureRecord (Name, ShellDescriptorRecord_id) VALUES (?, ?); select SCOPE_IDENTITY()] ---> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'Id', table 'carshop.dbo.Settings_ShellFeatureRecord'; column does not allow nulls. INSERT fails.
The statement has been terminated.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
   at NHibernate.Id.IdentityGenerator.InsertSelectDelegate.ExecuteAndExtract(IDbCommand insert, ISessionImplementor session)
   at NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
   --- End of inner exception stack trace ---
   at NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
   at NHibernate.Action.EntityIdentityInsertAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
   at NHibernate.Impl.SessionImpl.SaveOrUpdate(String entityName, Object obj)
   at NHibernate.Engine.CascadingAction.SaveUpdateCascadingAction.Cascade(IEventSource session, Object child, String entityName, Object anything, Boolean isCascadeDeleteEnabled)
   at NHibernate.Engine.Cascade.CascadeToOne(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
   at NHibernate.Engine.Cascade.CascadeAssociation(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
   at NHibernate.Engine.Cascade.CascadeProperty(Object parent, Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
   at NHibernate.Engine.Cascade.CascadeCollectionElements(Object parent, Object child, CollectionType collectionType, CascadeStyle style, IType elemType, Object anything, Boolean isCascadeDeleteEnabled)
   at NHibernate.Engine.Cascade.CascadeCollection(Object parent, Object child, CascadeStyle style, Object anything, CollectionType type)
   at NHibernate.Engine.Cascade.CascadeAssociation(Object parent, Object child, IType t
So the idea of adding a new module (a custom part developed) and testing it in dev machine (works) and deploying to shared hosting (and enabling the module) is not working. From the log, I see that it is a SQL Error.

Also, Other thing I've tried is, I used Visual Studio WebDeploy to deploy to a local folder on my machine. This also creates a source (App Data Excluded by option) and this site is 59.8MB compared to 86.6MB created by "ClickToBuild.cmd". Can anyone also tell me if there is a difference between these source in terms of what is a good way to deploy webistes?
  1. Use WebDeploy - Exclude App Data, Precompile While Deployment - to a local folder and then upload the source to serve
  2. Use same process above, but deploy directly to Shared Hosting folder by using Publish Settings for the Shared Host
  3. Make use of ClickToBuild.cmd EVERYTIME to deploy - This will always create new files and "Each" file in source will be uploaded by any FTP even if we say deploy only newer - because everything is new.
Any suggestions on the above is helpful. Thanks.
Mar 6, 2015 at 7:54 PM
Edited Mar 6, 2015 at 8:03 PM
Hi,

This article http://stackoverflow.com/questions/15919247/orchard-promoting-from-test-to-prod helped me see that Import/Export of database from local to production(some shared hosting) will copy data but not primary keys and so on.

I did Script out the database and execute the script on shared hosting Sql Server Database.

I get the following error:
2015-03-06 11:40:28,186 [7] Orchard.Exceptions.DefaultExceptionPolicy - (null) - An unexpected exception was caught
 (null)
System.NullReferenceException: Object reference not set to an instance of an object.
   at Orchard.Environment.Extensions.ExtensionManagerExtensions.<>c__DisplayClass2.<EnabledFeatures>b__0(FeatureDescriptor fd) in c:\myaspfiles\orchard\carshop\src\Orchard\Environment\Extensions\IExtensionManager.cs:line 18
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Orchard.Data.Migration.AutomaticDataMigrations.Activated() in c:\myaspfiles\orchard\carshop\src\Orchard\Data\Migration\AutomaticDataMigrations.cs:line 34
   at Orchard.Events.DelegateHelper.<>c__DisplayClass28`1.<BuildAction>b__27(Object target, Object[] p) in c:\myaspfiles\orchard\carshop\src\Orchard\Events\DelegateHelper.cs:line 110
   at Orchard.Events.Default
Can anyone please tell me what would be the proper way to upload the database. Here are the steps I have taken currently:
  1. Develop Orchard CMS website on local dev machine.
  2. use ClickToBuild.cmd to build a "Precompiled" version and upload it to Shared Hosting (in my case)
  3. The App_Data folder will have a _marker.txt for place holder. Thus, deploy the "initial real" database structure from dev machine to hosting by scripting.
    This is the step I am having issues with. The database is not scripted properly and I keep getting errors.
In my local machine I used a Sql Server Express database so yes, I've changed the App_Data/Default/Settings.txt to contain the proper connection string.
At step (2) when I upload to hosting via filezilla, I exclude App_Data and then after everything uploads, I copy the App_Data with structure to hosing (Default, Logs folders etc). I also make sure that Settings.txt in deployed version contains a connection string -> pointing to a database at hosting provider.

Can anyone please tell me "what is the proper way to get the initial database structure (orchard cms tables) in shared hosting"?
By this I mean, If you are using a SQL Express database in local machine for development, and then deploy orchard site to shared hosting - What do you do about the App_Data folder?
  1. Do we just make sure "Settings.txt" points to db in hosting provider (this is obvious)
  2. What happens when the Initial call hits the site? Does there need to be a DB structure? if so, how do we transfer from local to shared hosting (Scripting says finished with some errors - and I believe this is what is not setting up db properly. The schema only, not data).
    Thanks.
Mar 7, 2015 at 12:24 AM
Edited Mar 7, 2015 at 12:25 AM
The link below describes a situation that another guy was hit with same problem.

https://orchard.codeplex.com/discussions/546216

However, I could not find the solution.

My problem boils down to this:
  1. How to deploy a Sql Server Express database from local dev machine to production (shared hosting).
  2. SQL Server Management Studio, does not script the local dev orchard database properly. We always end up with Some errors. Also, SSMS Does not have Copy Database Wizard that PRO version has.
    Another solution for copying primary keys: http://williamsportwebdeveloper.com/cgi/wp/?p=153 as suggested by this article does not work.
P.S. I also tried deploying (by scripting and import data) for a Fresh installation database for Orchard. Thinking that with this version - the scripting errors would not come up. This did not work. Any database copy does not import primary keys.

Please help.

Thanks.
Mar 8, 2015 at 12:57 AM
Edited Mar 8, 2015 at 1:06 AM
Hi.

Have you tried Backup/Restore? This will preserve your keys. I'm not sure how this will work with shared hosting, but I use it with a dedicated server and it works just dandy.

Backup: https://msdn.microsoft.com/en-GB/library/ms187510.aspx

Use Media Options > Overwrite all existing backup sets

Restore: https://msdn.microsoft.com/en-GB/library/ms177429.aspx

You may need to re-bind your user(s) with ALTER USER <your user> WITH LOGIN = <your login>

Simples.
Mar 8, 2015 at 2:01 AM
Hi Troy,

Thanks for the reply.

I did see the point that no matter what options were there, I was using shared hosting and I can't control the database creation. The backup and restore option do not work since I am on shared and not dedicated hosting.

However, one bit of good news is, I use Arvixe for hosting and they do have Orchard CMS as an installation option. They also let us install on a virtual directory.
Here are the steps I've followed that are currently working (I need to retest this process - I'm reinstalling windows on my laptop and will try after)
  1. Develop an orchard CMS website in local development machine.
  2. On arvixe, create a virtual directory - and install Orchard CMS on that virtual directory using this process:
    http://blog.arvixe.com/how-to-install-orchard-cms-from-your-websitepanel-using-microsoft-web-app-gallery/
  3. The above process creates a database structure - which Is what I have having problems with.
  4. Now I delete all folders in hosting provider for the virtual directory - since I will upload these from local machine
  5. Use ClickToBuild.cmd and build (Stage/Precompiled) folders.
  6. Use the contents of Precompiled and upload to hosting provider with FileZilla
    • Note that here, precompiled will have a dummy App_Data folder with a _marker.txt (so this can be left out while uploading)
  7. Now upload local App_Data folder (and make sure Settings.txt is pointing a database on hosting provider - which was created on install in steps 2,3
  8. At this point - Orchard CMS website at Arvixe has the dummy site, but any custom modules we have uploaded will be pushed by filezilla.
  9. Also, now the Enable/Disable module works on Arvixe (shared hosting)
The above steps are working for me, and I have to retest the whole procedure again. For example, from local machine upload to Arvixe with custom part (module) 1.
Then in local machine develop custom part 2 and push that (by way of FTP) to hosting and see if 2nd module can be properly enabled.

Can anyone please tell me if they upload All folders like media? I'm thinking lets say the local folder has 2 video files for testing. But customers have uploaded 10 on production, at this point, would it be okay to "Not" push Media folders to hosting - if website does not depend on test content ?

Thanks for your advice.
Marked as answer by robroysd on 3/11/2015 at 11:28 AM
Mar 9, 2015 at 8:32 PM
Edited Mar 9, 2015 at 8:34 PM
The method discussed above is tested and working for me. New modules can be added and deployed by filezilla.

I also make note to set options in FileZilla for uploading any files that are newer or differ in size. This will skip unnecessary upload which is good.