MetadataException:连接字符串

时间:2013-01-31 19:44:51

标签: c# .net connection-string edmx

我意识到这个问题在此之前已被多次询问和解决,并且有很多有用的帖子,比如这个...... http://blogs.teamb.com/craigstuntz/2010/08/13/38628/ 但不幸的是,这些建议都没有对我有用,所以我发帖是希望有人可能发现我还没见过的东西。

我有一个数据库项目Sp_CodeGenerator - 我已连接到数据库。我的连接字符串是

<add name="AdWorksLTEntities" connectionString="metadata=res://*/Sp_CodeGenerator.Model1.csdl|res://*/Sp_CodeGenerator.Model1.ssdl|res://*/Sp_CodeGenerator.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=EIRCOM;Initial Catalog=AdventureWorksLT2008R2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework&quot;" providerName="System.Data.EntityClient"/>

我尝试将//*/Sp_CodeGenerator.Model...替换为dll //Sp_CodeGenerator/Sp_CodeGenerator.Model.csdl等名称,但它不起作用。

我还删除了.config文件中的所有引用,删除了实体框架生成的.edmx文件和模板文件并重启多次,但它不起作用。

我可以在我的目录结构中看到edmx文件:Model1.csdl,Model1.msl,Model1.ssdl位于名为edmxResourcesToEmbed的文件夹中,它们可以在C:\ Sp_CodeGenerator \ Sp_CodeGenerator \ obj \ x86中找到/ p>

所以完整的路径是             C:\ Sp_CodeGenerator \ Sp_CodeGenerator \ OBJ \ 86 \调试\ edmxResourcesToEmbed

我不确定这是不是巧合,但一旦问题出现,我也注意到,一旦打开.config文件,我就会收到几条消息,说明元素&#39; entityFramework&#39; &#39; defaultconnectionFactory&#39; &#39;类型&#39;等等。

任何关于下一步的建议,非常感谢。

MetadataException上的完整堆栈跟踪是

  at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.LoadResource()
  at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.CreateReader()
  at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.CreateReaders(DataSpace        spaceToGet)
   at System.Data.Metadata.Edm.MetadataArtifactLoaderComposite.CreateReaders(DataSpace  spaceToGet)
   at System.Data.Metadata.Edm.MetadataCache.EdmMetadataEntry.LoadEdmItemCollection(MetadataArtifactLoader loader)
   at System.Data.Metadata.Edm.MetadataCache.EdmItemCollectionLoader.LoadItemCollection(EdmMetadataEntry entry)
  at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry)
  at System.Data.Metadata.Edm.MetadataCache.GetOrCreateEdmItemCollection(String cacheKey, MetadataArtifactLoader loader, Object& entryToken)
  at System.Data.EntityClient.EntityConnection.LoadEdmItemCollection(MetadataWorkspace workspace, MetadataArtifactLoader artifactLoader)
  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.OrderBy[TSource,TKey](IQueryable`1 source, Expression`1 keySelector)
  at Sp_CodeGenerator.SelectAll.SelectAll_Method() in    C:\Sp_CodeGenerator\Sp_CodeGenerator\Templates\dbo.SelectAll.StoredProcedure.sql.xml.cs:line 14
  at Sp_CodeGenerator.Program.Main(String[] args) in C:\Sp_CodeGenerator\Sp_CodeGenerator\Program.cs:line 15
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
  at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  at System.Threading.ThreadHelper.ThreadStart()

1 个答案:

答案 0 :(得分:0)

我找到了解决方案 - 我只需要删除Sp_CodeGenerator。来自infront连接字符串中的每个Model1。不确定为什么连接字符串首先会像那样生成?也许与我的目录结构有关?