简体   繁体   中英

Add-Migration throws an SQL ConnectionString exception

I have a working application to who's DAL I just added EF5 migrations. While using Enable-Migrations and Add-Migrations, I get the following error.

Add-Migration EnforeUniqueIndexes

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.TypeInitializationException: The type initializer for 'Parkalot.Database.Context' threw an exception. --->
System.ArgumentException: The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.

I suspect that it is trying to connect to the database but the connection is not defined in that project. It is defined in another assembly that acts as the BLL and passes the connection string to the DAL.

I do not want to keep a copy of the connection string in the DAL (in app settings or in code) and am not sure how to fix this. Please advise.

UPDATE: This is multi-tenant SaaS application so the DAL needs to be invoked with different connection strings based on context.

Found the answer here: http://coding.abel.nu/2012/03/ef-migrations-command-reference/#Add-Migration .

I still did have to add the connection string to the DAL project but only for the package manager to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM