EDMX连接字符串“名称” [英] EDMX Connectionstring 'name'

查看:84
本文介绍了EDMX连接字符串“名称”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经通过Edmx生成了以下连接字符串:

We have generated this connectionstring (below) via Edmx:

   <add name="Connection" connectionString="metadata=res://*/Code.aa.csdl|res://*/Code.aa.ssdl|res://*/Code.aa.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=server.com;initial catalog=db_name;persist security info=True;user id=user;password=pwd;multipleactiveresultsets=True;application name=EntityFramework;&quot;" providerName="System.Data.EntityClient" />

但是,运行该应用程序将获得以下消息:

However, running the application will get us the following message:

System.ArgumentException:参数'name'不能为null,为空或仅包含空格。

我在连接字符串中没有看到任何错误的空格。

I don't see any whitespace that is wrong in the connection string. What is causing this?

StackTrace:

StackTrace:

ij System.Data.Entity.Utilities.Check.NotEmpty(字符串值,字符串parameterName)
bij System.Data.Entity.Core.Metadata.Edm.EdmMember..ctor(字符串名称,TypeUsage memberTypeUsage)
bij System.Data.Entity.Core.Metadata.Edm .EdmProperty..ctor(字符串名称,TypeUsage typeUsage)
bij

ij System.Data.Entity.Utilities.Check.NotEmpty(String value, String parameterName) bij System.Data.Entity.Core.Metadata.Edm.EdmMember..ctor(String name, TypeUsage memberTypeUsage) bij System.Data.Entity.Core.Metadata.Edm.EdmProperty..ctor(String name, TypeUsage typeUsage) bij

System.Data.Entity.Core.Metadata.Edm.Converter.ConvertToProperty(StructuredProperty somProperty, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.ConvertToEntityType(SchemaEntityType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.LoadSchemaElement(SchemaType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.ConvertToEntitySet(EntityContainerEntitySet set, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.ConvertToEntityContainer(EntityContainer element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.LoadSchemaElement(SchemaType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.ConvertSchema(Schema somSchema, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary`2 newGlobalItems)
   bij System.Data.Entity.Core.Metadata.Edm.Converter.ConvertSchema(IList`1 somSchemas, DbProviderManifest providerManifest, ItemCollection itemCollection)
   bij System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadSomSchema(IList`1 somSchemas, DbProviderManifest providerManifest, ItemCollection itemCollection)
   bij System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadItems(DbProviderManifest manifest, IList`1 somSchemas, ItemCollection itemCollection)
   bij System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer`2& cachedCTypeFunction)
   bij System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
   bij System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
   bij System.Data.Entity.Core.Metadata.Edm.MetadataCache.<>c__DisplayClass5.<>c__DisplayClass7.<GetMetadataWorkspace>b__1()
   bij System.Lazy`1.CreateValue()
   bij System.Lazy`1.LazyInitValue()
   bij System.Lazy`1.get_Value()
   bij System.Data.Entity.Core.Metadata.Edm.MetadataCache.<>c__DisplayClass5.<>c__DisplayClass7.<GetMetadataWorkspace>b__4()
   bij System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadAndCheckItemCollection[T](Func`1 itemCollectionLoader)
   bij System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.<>c__DisplayClass16.<.ctor>b__f()
   bij System.Lazy`1.CreateValue()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bij System.Lazy`1.get_Value()
   bij System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required)
   bij System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace)
   bij System.Data.Entity.Core.Objects.ObjectContext.InitializeMappingViewCacheFactory(DbContext owner)
   bij System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory)
   bij System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection)
   bij System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
   bij System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
   bij System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   bij System.Data.Entity.Internal.InternalContext.Initialize()
   bij System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   bij System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   bij System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   bij System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   bij System.Linq.Queryable.OrderByDescending[TSource,TKey](IQueryable`1 source, Expression`1 keySelector)
   bij TPO.Code.TpoFunctions.getLastReleaseDate() in regel 930
   bij TPO.Global.Application_Start(Object sender, EventArgs e) in Global.asax.cs:regel 67

调用的函数:

 protected void Application_Start(object sender, EventArgs e)
        {
      using (var db = new Foo_Bar())
                {
                    var release = (from a in db.Release
                                   orderby a.R_ReleaseDatum descending
                                   select a).FirstOrDefault();

                    _LastReleaseDate = release.R_ReleaseDatum.Value;
                }
}

Foo_Bar DbContext派生类的定义

Definition of the Foo_Bar DbContext-derived class

public partial class Foo_Bar : DbContext
    {
        public Foo_Bar()
            : base("name=Connection")
        {
        }
    }


推荐答案

该异常由 DbContext 基类的构造函数引发。您派生的上下文类无需连接字符串即可初始化。应该是这样的:

That exception is thrown by the DbContext base class's constructor. Your derived context class is initialized without connection string. It should be something like this:

public class YourContext : DbContext
{
    public YourContext() 
        : base("Foo_Bar")
    {
    }
}

这篇关于EDMX连接字符串“名称”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆