" ConnectionString属性尚未初始化&QUOT。 - 但只有当发布 [英] "The ConnectionString property has not been initialized." - but only when publishing

查看:396
本文介绍了" ConnectionString属性尚未初始化&QUOT。 - 但只有当发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完美的运行使用的LocalDB我的开发机器上MVC5 / EF6.1网站。

I have an MVC5 / EF6.1 website that runs perfectly on my development machine using LocalDb.

不过,我出版这一个网站的Azure与SQL Azure的数据库时,我做的任何数据库交互的时候,收到以下错误:

However, when I publish this to an Azure Website with an Azure SQL Database, I get the following error when doing any database interaction:

ConnectionString属性尚未初始化。

我已经找遍了,不能找到这种情况的发生在Azure上的原因。

I've searched all over and can't find the reason that this happens on Azure.

第一个文件堆栈跟踪点为 IdentityModels.cs:45

The first file the stack trace points to is IdentityModels.cs:45

这包含以下内容:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext() : base("DefaultConnection")
    {

    }
}

当我发布到Azure的我测试过的连接字符串(回来OK),这是设置屏幕:

When I publish to Azure I've tested the connection string (comes back OK), and this is the Settings screen:

任何想法,这是怎么回事?

Any idea as to what is going on?

更新:

如果不选择 ApplicationDbContext ,而是选择 DefaultConnection 它的工作原理,但我不能使用code首先迁移。我怎样才能获得 ApplicationDBContext 重新工作?

If don't select ApplicationDbContext and instead select DefaultConnection it works, however I won't be able to use code first migrations. How can I get the ApplicationDBContext to work again?

推荐答案

有关其他人谁运行到这个问题 - 我发现我的解决方案

For anyone else who runs into this problem - I found my solution.

我刚刚升级的 ASP身份通过的NuGet ,以版本2.0.0,当它安装在 Microsoft.AspNet.Identity.EntityFramework 封装它改变了我的发布设置和分开的 AppliationDbContext DefaultConnectionString ,这是什么原因造成的问题。

I had just upgraded ASP Identity to version 2.0.0 via Nuget, and when it installed the Microsoft.AspNet.Identity.EntityFramework package it changed my publish settings and seperated the AppliationDbContext and the DefaultConnectionString and this is what caused the problem.

我不得不这样做是字面上一样容易更改以下到我的 ApplicationDbContext

What I had to do was literally as easy as to change the following to my ApplicationDbContext

ASP身份1.0.0

public ApplicationDbContext() : base("DefaultConnection")
{

}

ASP身份2.0.0

// Set the throwIfV1Schema to false...
public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
{

}

我不知道为什么这并没有影响我的本地开发的版本,但它解决了我的问题。希望这可以帮助别人!

I have no idea why this didn't affect my local development version, but it's solved my issue. Hope this helps someone!

这篇关于&QUOT; ConnectionString属性尚未初始化&QUOT。 - 但只有当发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆