Exception: System.ArgumentException: Keyword not supported: 'initial catalog' when hard co

I have hard coded my connection string to the dbcontext of Entity Framework DB first.

public MirrorBranchesEntities(string connectionStringName, string db) : base(@"name=" + connectionStringName + " connectionString=metadata=res://*/MirrorBranches.csdl|res://*/MirrorBranches.ssdl|res://*/MirrorBranches.msl;provider=System.Data.SqlClient;provider connection string=data source=(local);initial catalog=" + db + ";user id=sa;password=Qwer0987;MultipleActiveResultSets=True;App=EntityFramework; providerName=System.Data.EntityClient") { }

There are multiple databases that uses that connection string. The problem is that it is returning an exception

System.ArgumentException: Keyword not supported: 'initial catalog'. at System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Hashtable synonyms) at System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms) at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) at System.Data.Entity.Core.EntityClient.EntityConnection..ctor(String connectionString) at System.Data.Entity.Internal.LazyInternalConnection.Initialize() at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() at System.Data.Entity.Internal.Linq.InternalSet1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) at System.Data.Entity.Internal.Linq.InternalSet1.Add(Object entity) at System.Data.Entity.DbSet`1.Add(TEntity entity)


I have updated my connection string -- took away the double metadata attribute and removed an extra single-quote

I am trying to put the connection string in an EntityConnectionStringBuilder but could not insert it in the context.

public static MirrorBranchesEntities ConnectToSqlServer(string catalog) { var sqlBuilder = new SqlConnectionStringBuilder { DataSource = "(local)", InitialCatalog = catalog, PersistSecurityInfo = true, IntegratedSecurity = true, MultipleActiveResultSets = true, UserID = "sa", Password = "Qwer0987" }; var entityConnectionStringBuilder = new EntityConnectionStringBuilder { Provider = "System.Data.EntityClient", ProviderConnectionString = sqlBuilder.ConnectionString, Metadata = "res://*/MirrorBranches.csdl|res://*/MirrorBranches.ssdl|res://*/MirrorBranches.msl", }; return new MirrorBranchesEntities(entityConnectionStringBuilder.ConnectionString, sqlBuilder.InitialCatalog); }

then I changed my context to base(ConnectToSqlServer(connectionStringName,db)) but it says invalid arguments.


Check your value. In your example there is doubled metadata= expression. Also try to use quotes inside your string:

base("name=" + connectionStringName + "connectionString='metadata=res://*/MirrorBranches.csdl|res://*/MirrorBranches.ssdl|res://*/MirrorBranches.msl;provider=System.Data.SqlClient;provider connection string=data source=(local);initial catalog=" + db + ";user id=sa;password=Qwer0987;MultipleActiveResultSets=True;App=EntityFramework'"; providerName=System.Data.EntityClient")


  • Web API not returning any data result
  • EntityFramework Model-First metadata for breezejs
  • Proper format for SQL Server Connection String on 1and1.com
  • Splitting an Solution into multiple projects
  • Encoding=ASCII; and Encoding=UNICODE; do not work in an Npgsql 3 connection string
  • Connection string between IIS and SQL server
  • Boostraping symfony 2 for pthread from command
  • What is wrong with this mysql connection string?
  • Entity Framework: Unknown column in 'where clause
  • Add custom information to HockeyApp crash report
  • updating and compacting sqlite database in android
  • Is it good to have multiple database running in a same project?
  • parameterized queries in oursql
  • Parse Framework with Swift
  • MySQL: Difference between `… ADD INDEX(a); … ADD INDEX(b);` and `… ADD INDEX(a,b);`?
  • How do I Dispose a HttpResponseMessage in my Web Api Method?
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Extracting HTML between tags
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Android screen density dpi vs ppi
  • Nant, Vault & Windows Integrated Authentication
  • Regex thinks I'm nesting, but I'm not
  • Fetching methods from BroadcastReceiver to update UI
  • Bug in WPF DataGrid
  • TFS: Get latest causes slow project reloading
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Controls, properties, events and timers running in design time
  • javascript inside java/jsp code
  • Running a C# exe file
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • ORA-29908: missing primary invocation for ancillary operator
  • Android Studio and gradle
  • C# - Getting references of reference
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can i traverse a binary tree from right to left in java?
  • Converting MP3 duration time
  • java string with new operator and a literal