我们已经通过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="data source=server.com;initial catalog=db_name;persist security info=True;user id=user;password=pwd;multipleactiveresultsets=True;application name=EntityFramework;"" providerName="System.Data.EntityClient" />
但是,运行该应用程序将收到以下消息:
&#34; System.ArgumentException:参数&#39; name&#39;不能为空,空或仅包含空格。&#34;
我没有在连接字符串中看到任何错误的空格。造成这种情况的原因是什么?
堆栈跟踪:
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派生类的定义
public partial class Foo_Bar : DbContext
{
public Foo_Bar()
: base("name=Connection")
{
}
}
答案 0 :(得分:2)
DbContext
基类的构造函数抛出了该异常。您的派生上下文类已初始化,没有连接字符串。它应该是这样的:
public class YourContext : DbContext
{
public YourContext()
: base("Foo_Bar")
{
}
}