Commerce-atrix

You just extended the standard Microsoft Commerce Server 2007 order objects, oh, say maybe the OrderForm. Maybe the LineItem. Now, you find yourself staring down an ASP.NET error that looks eerily similar to this:

I apologize in advance for the text flying out of it’s container, but, WordPress does not enjoy exceptional content. Ha! Punny.

Exception information:     Exception type: InvalidCastException     Exception message: Unable to cast object of type 'System.DBNull' to type 'System.String'. Stack trace:     at Microsoft.CommerceServer.Runtime.Orders.OrderContext.ValidateXmlFileWithSql(SchemaMapping mapping, String connStr, Int32 timeout)     at Microsoft.CommerceServer.Runtime.Orders.OrderContext.CreateSchemaAndPipelineMapping(SchemaMapping& schemaMapping, PipelineAdapter& pipelineAdapter, String appRootPath, CommerceOrdersConfiguration ordersConfiguration)     at Microsoft.CommerceServer.Runtime.Orders.OrderContext.Initialize(String transactionResourceConnectionString, String transactionConfigResourceConnectionString)     at Microsoft.CommerceServer.Runtime.Orders.OrderContext.Create(String transactionResourceConnectionString, String transactionConfigResourceConnectionString)     at Microsoft.CommerceServer.Runtime.Orders.CommerceOrderModule.CreateOrderContext()     at Microsoft.CommerceServer.Runtime.Orders.CommerceOrderModule.get_OrderContext()     at Microsoft.CommerceServer.Runtime.Orders.CommerceOrderModule.OnBeginRequest(Object sender, EventArgs e)     at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Well, what Microsoft didn’t tell you is that your RunTimeUser needs more permissions to the SiteName_transactions database than they mention in their setup documentation.

ORLY? RLY.

Try giving RunTimeUser the role membership of dbddladmin to the SiteNametransactions database. Maybe then Reset IIS.

Does it work?

Yeah. That’s the good stuff.

I’m loathe to recommend this, but it’s the only way around this issue I could find. I generally use SQL default syntax in order to ensure that items get set in non-nullable columns when extending the orders system, and also ensure that the value is initialized in the extended class.

As such, the error of mapping from DBNull to string doesn’t make a lot of sense. If someone could shed more light on the subject, it would certainly be appreciated.

EDIT (5.2.2010):

It would seem the issue was solved care of Justin Miller in the comments:

What is happening is Commerce Server runs

SP_HelpConstraints (a system stored procedure) and it returns a list of all constraints / keys on a table. Well, if your default is (NULL) … this helper stored proc actually returns (NULL) … and apparently commerce server code is written so poorly that it bombs out trying to convert that (NULL) value to a string!!!