我需要連接到Orchard的其中一個模塊中的遠程數據庫,以便通過實體框架獲取和保存數據。將實體框架添加到模塊
我的問題是建立並運行連接。嘗試時出現異常。
一些谷歌技能後,我認爲問題是連接字符串。但我不知道該寫什麼。我已經嘗試了一切。
<add name="lvbb_dbEntities" connectionString="metadata=res://*/Services.Database.LvbbDataModel.csdl|res://*/Services.Database.LvbbDataModel.ssdl|res://*/Services.Database.LvbbDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=databaseurl;initial catalog=lvbb_db;persist security info=True;user id=username;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
堆棧跟蹤:
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)
at System.Data.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
at System.Data.Common.Utils.Memoizer`2.Result.GetValue()
at System.Data.Common.Utils.Memoizer`2.Evaluate(TArg arg)
at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
at System.Data.Objects.ObjectContext..ctor(EntityConnection connection)
at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
at Allvinskan.LVBBFunctions.Services.SaveDatabaseService.SaveUserModel(EditUserViewModel model) in c:\tfsOnline\Allvinskan\LVBB\X\src\Orchard.Web\Modules\Allvinskan.LVBBFunctions\Services\SaveDatabaseService.cs:line 16
at Allvinskan.LVBBFunctions.Controllers.UserController.EditUser(EditUserViewModel model) in c:\tfsOnline\Allvinskan\LVBB\X\src\Orchard.Web\Modules\Allvinskan.LVBBFunctions\Controllers\UserController.cs:line 64
這個堆棧跟蹤中沒有任何東西來自Orchard,所以它可能是一個純粹的EF配置問題。 –
我實際上通過向模塊添加實體框架來解決它。但爲了使所有配置都能正常工作,我將連接字符串和其他webcofig添加到了Orchard.Web web.config。 – Madelene