简体   繁体   English

Add-Migration引发SQL ConnectionString异常

[英]Add-Migration throws an SQL ConnectionString exception

I have a working application to who's DAL I just added EF5 migrations. 我有一个适用于谁的DAL的应用程序,我刚刚添加了EF5迁移。 While using Enable-Migrations and Add-Migrations, I get the following error. 使用Enable-Migrations和Add-Migrations时,出现以下错误。

Add-Migration EnforeUniqueIndexes

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.TargetInvocationException:调用的目标引发了异常。 ---> ->
System.TypeInitializationException: The type initializer for 'Parkalot.Database.Context' threw an exception. System.TypeInitializationException:“ Parkalot.Database.Context”的类型初始值设定项引发了异常。 ---> ->
System.ArgumentException: The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. System.ArgumentException:参数'nameOrConnectionString'不能为null,为空或仅包含空格。

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. 它在另一个程序集中定义,该程序集充当BLL,并将连接字符串传递给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. 我不想在DAL中(在应用程序设置或代码中)保留连接字符串的副本,并且不确定如何解决此问题。 Please advise. 请指教。

UPDATE: This is multi-tenant SaaS application so the DAL needs to be invoked with different connection strings based on context. 更新:这是多租户SaaS应用程序,因此需要根据上下文使用不同的连接字符串调用DAL。

Found the answer here: http://coding.abel.nu/2012/03/ef-migrations-command-reference/#Add-Migration . 在此处找到了答案: 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. 我仍然必须将连接字符串添加到DAL项目中,但仅供包管理器使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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