为什么我的MVC 5应用程序尝试访问本地数据库 [英] Why is my MVC 5 application trying to access Local DB

查看:52
本文介绍了为什么我的MVC 5应用程序尝试访问本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在本地计算机上开发MVC 5应用程序,并且刚刚尝试向Azure公开测试版本,我发现了这个新错误.我的连接字符串没有引用LocalDB,在我的代码中找不到想要创建或访问LocalDB的任何内容.但是我收到与尝试创建/访问localDB有关的错误:

I have been developing an MVC 5 application on my local machine, and having just tried to public a test version to Azure, I have found this new error. My connection strings have no reference to a LocalDB, and I can't find anything in my code that wants to create or access a LocalDB. Yet I am receiving an error related to an attempt to create/access localDB:

连接字符串使用应用程序的App_Data目录中的数据库位置指定本地Sql Server Express实例

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory

最初,该项目具有表单身份验证,但是后来我更改为AspNetIdentity框架.我担心我从初始模板中获得了一些残留的表单身份验证,尽管对应用程序进行了多次梳理和冗长的搜索,但我仍然找不到.

Originally the project had forms authentication, but I later changed to AspNetIdentity framework. I'm concerned I've got some residue from the initial template with forms authentication that I cannot find despite combing the application several times and googling at length.

这是连接字符串.没有其他人了.至少使用Visual Studio中的find函数来查找"connectionString"-这就是全部:

Here are the connection strings. There are no others. At least using a find function in Visual studio to look for "connectionString" - this is all:

<add name="elmah" connectionString="Data Source=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx" providerName="System.Data.SqlClient" />
<add name="IdentityDbContext" connectionString="Data Source=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx" providerName="System.Data.SqlClient" />
<add name="ORLODbContext" connectionString="metadata=res://*/ORLODbContext.csdl|res://*/ORLODbContext.ssdl|res://*/ORLODbContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx&quot;" providerName="System.Data.EntityClient" />

我的谷歌搜索功能使我不得不将其他功能添加到web.config中.在system.web:

My googling has led me to add these other features to the web.config. In the system.web:

<authentication mode="None" />
<membership>
  <providers>
    <clear />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
  </providers>
</profile>

在这里,我的谷歌搜索功能还建议我添加:

Here, my googling also suggests I should add:

<roleManager>
  <providers>
    <clear />
  </providers>
</roleManager>

但是,如果执行此操作,则会出现错误:

But if I do this, I get the error:

找不到默认角色提供程序.

Default Role Provider could not be found.

看来,由于我不想一个,所以我想也许我不需要这一点了.但是,如果我错了,请纠正我.

Seeing as I don't want one, it seems, I thought maybe I don't need this bit. But please correct me if I'm wrong.

还有什么我应该看的吗?

Is there anything else I should look at?

推荐答案

Asp.Net默认情况下使用角色管理器,即使在使用Identity时也是如此.解决方案是完全禁用它.在您的web.config中,删除整个roleManager部分,并将其替换为:

Asp.Net by default uses the role manager, even when working with Identity. The solution is to disable it completely. In your web.config remove the entire roleManager section and replace it with:

<roleManager enabled="false" />

有关其他信息,在您的machine.config中,您可能会有这样的一行:

For some further info, in your machine.config you likely have a line like this:

<add name="AspNetSqlRoleProvider"
    connectionStringName="LocalSqlServer" applicationName="/" type="..."/>

还有这样的连接字符串:

And a connection string like this:

<add name="LocalSqlServer" 
    connectionString="...localdb..." 
    providerName="System.Data.SqlClient"/>

因此,将角色管理器条目保留在那里,使Asp.Net在您的IdentityDbContext之前开始在此本地数据库中查找.删除条目意味着它会尝试对条目进行罚款,但会失败.因此,唯一的解决方案是完全禁用它.

So leaving the role manager entries in there make Asp.Net start looking in this local db before your IdentityDbContext. Removing the entries means it tries to fine an entry and fails. So the only solution is to disable it completely.

这篇关于为什么我的MVC 5应用程序尝试访问本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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