Problem working on multiple databases

Feb 5, 2014 at 10:33 AM
Hi,

Working Environment : NOF 5.6, Net 4.0, VS2010, MVC4 and EF5
I have done the following steps for creating two databases:

I have created two DbContext for example : ModelCContext and ModelDContext

In Web.cong file I put the following connectionStrings :

<add name="ModelCContext " connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;multipleactiveresultsets=true;Initial Catalog = DB1;" providerName="System.Data.SqlClient" />

<add name="ModelDContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;multipleactiveresultsets=true;Initial Catalog = DB2;" providerName="System.Data.SqlClient" />

And in RunWeb class I've initialize the two databases :

protected override IObjectPersistorInstaller Persistor {
get {
var p = new EntityPersistorInstaller();
p.UsingCodeFirstContext(() => new ModelCContext());
p.UsingCodeFirstContext(() => new ModelDContext());
return p;
}
}

Using these steps two databases and their corresponding tables are created.
But problem is when I want to save something error occurs:
Stack Trace:
[SqlException (0x80131904): MSDTC on server 'ELMA-PC\SQLEXPRESS' is unavailable.]
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.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) +716
System.Data.SqlClient.TdsParser.GetDTCAddress(Int32 timeout, TdsParserStateObject stateObj) +51
System.Data.SqlClient.SqlInternalConnectionTds.GetDTCAddress() +25
System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx) +428
System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx) +133
System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction) +5009101
System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) +36
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1211
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.SqlClient.SqlConnection.Open() +125
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +52

[EntityException: The underlying provider failed on Open.]
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +161
System.Data.EntityClient.EntityConnection.Open() +98
System.Data.Objects.ObjectContext.EnsureConnection() +81
System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) +489
NakedObjects.EntityObjectStore.EntityObjectStore.SaveChanges(LocalContext context) +86
NakedObjects.Architecture.Util.CollectionUtils.ForEach(IEnumerable1 toIterate, Action1 action) +210
NakedObjects.EntityObjectStore.EntityObjectStore.Save() +101
NakedObjects.EntityObjectStore.EntityObjectStore.RecurseUntilAllChangesApplied(Int32 depth) +413
NakedObjects.EntityObjectStore.EntityObjectStore.RecurseUntilAllChangesApplied(Int32 depth) +457
NakedObjects.EntityObjectStore.EntityObjectStore.EndTransaction() +638
NakedObjects.Persistor.Objectstore.ObjectStoreTransaction.Commit() +173
NakedObjects.Persistor.Objectstore.ObjectStoreTransactionManager.EndTransaction() +106
NakedObjects.Persistor.Objectstore.ObjectStorePersistor.EndTransaction() +67
NakedObjects.Web.Mvc.Controllers.NakedObjectsController.OnActionExecuted(ActionExecutedContext filterContext) +108
NakedObjects.Web.Mvc.Controllers.GenericControllerImpl.OnActionExecuted(ActionExecutedContext filterContext) +86
System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) +9
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +265
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +12
System.Web.Mvc.Async.WrappedAsyncResult1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +126
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +45
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
System.Web.Mvc.Async.WrappedAsyncResult1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +61
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
System.Web.Mvc.Async.WrappedAsyncResult
1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +49
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +49
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Please suggest me what to do now.

Thanks.
Coordinator
Feb 5, 2014 at 11:43 AM
This is not a Naked Objects issue, it is because MSDTC (Microsoft Distributed Transactions) is not supported on SQL Express by default.

This posting might help:

http://alexduggleby.com/2008/08/24/msdtc-unavailable-for-sql-express-transactions-or-who-took-my-msdtc-settings-on-vista/

If not, search Stack Overflow or other forums for how to get MSDTC working on SQL Express.
Marked as answer by Elma_Cse on 2/6/2014 at 9:20 AM
Feb 6, 2014 at 4:22 PM
Thanks Richard for your suggestion. My problem is solved.