EDMX Connectionstring 'name'

我的未来我决定 提交于 2019-12-24 00:57:55

问题


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: The argument 'name' cannot be null, empty or contain only white space."

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

StackTrace:

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

Function called:

 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;
                }
}

Definition of the Foo_Bar DbContext-derived class

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

回答1:


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")
    {
    }
}


来源:https://stackoverflow.com/questions/28023224/edmx-connectionstring-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!