Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架连接字符串错误_C#_Entity Framework_Connection String - Fatal编程技术网

C# 实体框架连接字符串错误

C# 实体框架连接字符串错误,c#,entity-framework,connection-string,C#,Entity Framework,Connection String,我正在实体框架5中使用此连接字符串: <connectionStrings> <add name="RBSDbContext" connectionString="data source=.;MultipleActiveResultSets=true;initial catalog=RBS; Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

我正在实体框架5中使用此连接字符串:

<connectionStrings>
<add name="RBSDbContext" connectionString="data source=.;MultipleActiveResultSets=true;initial catalog=RBS; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
以这种方式添加内容也可以:

 ctx.Set<Category>.Add(new Category {Name="Another" });
 ctx.SaveChanges();

有人能帮助或解释为什么它对一方有效而对另一方无效吗?为什么它会抱怨连接字符串?

“attachdbfilename”是connectionstring的属性,在数据源中是数据库服务器name@Niks我没有在连接字符串中使用该属性。
 ctx.Set<Category>.Add(new Category {Name="Another" });
 ctx.SaveChanges();
public T Add<T>(T item, bool commit = false) where T : class
{
        var aSet = this.Set<T>();

        aSet.Add(item);

        if (commit)
        {
            SaveChanges();
        }

    return item;
}
Repo.Add<Category>(new Category { Name = "Repo" }, true);
[ArgumentException: Invalid value for key 'attachdbfilename'.]
System.Data.SqlClient.SqlConnectionString.VerifyLocalHostAndFixup(String& host, Boolean     enforceLocalHost, Boolean fixup) +907230
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +4116
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +150
System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +59
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
System.Data.SqlClient.SqlConnection..ctor(String connectionString) +26
System.Data.Entity.Infrastructure.SqlConnectionFactory.CreateConnection(String nameOrConnectionString) +382
System.Data.Entity.Infrastructure.LocalDbConnectionFactory.CreateConnection(String nameOrConnectionString) +392
System.Data.Entity.Internal.LazyInternalConnection.Initialize() +581
System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName() +31
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +363
System.Data.Entity.Internal.InternalContext.Initialize() +31
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +34
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +124
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +33
System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +226
System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity) +228
System.Data.Entity.DbSet`1.Add(TEntity entity) +72