I've just deployed a new application in ASP.Net MVC 4. I use a SQL Server 2008 R2 (NOT SQL Express).
我刚刚在ASP.Net MVC 4中部署了一个新的应用程序。我使用的是SQL Server 2008 R2(不是SQL Express)。
It worked good for the first 10 minutes, then I did a little change in the code and re-deployed it.
它在前10分钟工作得很好,然后我对代码做了一些改动并重新部署了它。
Now, whenever I try to access a page that uses SimpleMembership, I get this error:
现在,每当我尝试访问使用SimpleMembership的页面时,我都会收到此错误:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:SQLExpress数据库文件自动创建错误:连接字符串使用应用程序的App_Data目录中的数据库位置指定本地Sql Server Express实例。提供程序尝试自动创建应用程序服务数据库,因为提供程序确定数据库不存在。要成功检查应用程序服务数据库是否存在并自动创建应用程序服务数据库,必须满足以下配置要求:
But, I do not use SQL Server Express. In my web.config
I've set all the connection strings as follows:
但是,我不使用SQL Server Express。在我的web.config中,我设置了所有连接字符串,如下所示:
<add name="ApplicationServices"
connectionString="Server=myServer;Database=myDB;User Id=myUserID;Password=myPWD;"
providerName="System.Data.SqlClient" />
<add name="ApplicationServices"
connectionString="Server=myServer;Database=myDB;User Id=myUserID;Password=myPWD;"
providerName="System.Data.SqlClient" />
Why does it keep trying to create a SQL Server EXPRESS database?
为什么一直在尝试创建SQL Server EXPRESS数据库?
2 个解决方案
#1
4
When I encountered this error, it turned out to be simple. I finally figured out that in my _Layout.cshtml I was referencing User.IsInRole("role")
but after a Request.isAuthenticated
. My code looked something like @if (Request.isAuthenticated && User.IsInRole("role"))
. So basically if I wasn't signed in the home page would render since it would not traverse to the IsInRole()
call (which requires the simple membership to be initialized, otherwise I would get the error you mention here. So basically I needed to ensure that each and every controller that uses a view that extends the _Layout file and could have unauthenticated users, needs to have a [InitializeSimpleMembership]
. Or one of the various ways to Initialize Simple Membership.
当我遇到这个错误时,结果很简单。我终于发现在我的_Layout.cshtml中我引用了User.IsInRole(“role”)但是在Request.isAuthenticated之后。我的代码看起来像@if(Request.isAuthenticated && User.IsInRole(“role”))。所以基本上如果我没有登录主页会渲染,因为它不会遍历到IsInRole()调用(这需要初始化简单的成员资格,否则我会得到你在这里提到的错误。所以基本上我需要确保使用扩展_Layout文件的视图并且可能具有未经身份验证的用户的每个控制器都需要具有[InitializeSimpleMembership]。或者初始化简单成员资格的各种方法之一。
So something like
所以像
namespace ProjectName.Controllers
{
[InitializeSimpleMembership]
public class HomeController : Controller {
...
Also, I would often Ctrl + F5 to start the application and then use "Rebuild Solution" after. When I refreshed a page that wasn't the root home page, I would get the error until I would call the root home page. At that point, everything would start working again.
此外,我经常按Ctrl + F5启动应用程序,然后使用“重建解决方案”。当我刷新一个不是根主页的页面时,我会收到错误,直到我调用根主页。那时,一切都会重新开始。
Hopefully this will help you or someone. I banged my head for at least an hour or two.
希望这会对你或某人有所帮助。我把头撞了一两个小时。
#2
4
Are you still having this issue? Also, why do you have ApplicationServices listed twice?
你还有这个问题吗?另外,为什么要将ApplicationServices列出两次?
I ran into the same thing a while back. I was missing the config in web.config for membership and roles.
我不久前遇到了同样的事情。我在web.config中缺少配置和角色的配置。
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="Test" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="SqlRoleManager">
<providers>
<add name="SqlRoleManager"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices"
applicationName="Test" />
</providers>
</roleManager>
#1
4
When I encountered this error, it turned out to be simple. I finally figured out that in my _Layout.cshtml I was referencing User.IsInRole("role")
but after a Request.isAuthenticated
. My code looked something like @if (Request.isAuthenticated && User.IsInRole("role"))
. So basically if I wasn't signed in the home page would render since it would not traverse to the IsInRole()
call (which requires the simple membership to be initialized, otherwise I would get the error you mention here. So basically I needed to ensure that each and every controller that uses a view that extends the _Layout file and could have unauthenticated users, needs to have a [InitializeSimpleMembership]
. Or one of the various ways to Initialize Simple Membership.
当我遇到这个错误时,结果很简单。我终于发现在我的_Layout.cshtml中我引用了User.IsInRole(“role”)但是在Request.isAuthenticated之后。我的代码看起来像@if(Request.isAuthenticated && User.IsInRole(“role”))。所以基本上如果我没有登录主页会渲染,因为它不会遍历到IsInRole()调用(这需要初始化简单的成员资格,否则我会得到你在这里提到的错误。所以基本上我需要确保使用扩展_Layout文件的视图并且可能具有未经身份验证的用户的每个控制器都需要具有[InitializeSimpleMembership]。或者初始化简单成员资格的各种方法之一。
So something like
所以像
namespace ProjectName.Controllers
{
[InitializeSimpleMembership]
public class HomeController : Controller {
...
Also, I would often Ctrl + F5 to start the application and then use "Rebuild Solution" after. When I refreshed a page that wasn't the root home page, I would get the error until I would call the root home page. At that point, everything would start working again.
此外,我经常按Ctrl + F5启动应用程序,然后使用“重建解决方案”。当我刷新一个不是根主页的页面时,我会收到错误,直到我调用根主页。那时,一切都会重新开始。
Hopefully this will help you or someone. I banged my head for at least an hour or two.
希望这会对你或某人有所帮助。我把头撞了一两个小时。
#2
4
Are you still having this issue? Also, why do you have ApplicationServices listed twice?
你还有这个问题吗?另外,为什么要将ApplicationServices列出两次?
I ran into the same thing a while back. I was missing the config in web.config for membership and roles.
我不久前遇到了同样的事情。我在web.config中缺少配置和角色的配置。
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="Test" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="SqlRoleManager">
<providers>
<add name="SqlRoleManager"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices"
applicationName="Test" />
</providers>
</roleManager>