我刚在ASP.net MVC4
创建了一个新的VS2010
互联网应用程序。点击注册或登录链接时,浏览器会遇到异常(请参阅下文)。我没有对代码进行任何改动。我有Vislual Studio Professional 2010
的新安装。在以前的安装中,一切正常。
代码行抛出异常
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref
_initializerLock);
详细方法在这里
namespace MvcApplication1.Filters
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple
= false, Inherited = true)]
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
{
private static SimpleMembershipInitializer _initializer;
private static object _initializerLock = new object();
private static bool _isInitialized;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Ensure ASP.NET Simple Membership is initialized only once per app start
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
}
private class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
Database.SetInitializer<UsersContext>(null);
try
{
using (var context = new UsersContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity
Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
例外的细节是
Server Error in '/' Application.
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)
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.
Exception Details: System.Data.SqlClient.SqlException: 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)
答案 0 :(得分:0)
您似乎没有正在运行的SQL数据库实例。检查web.config中的连接字符串,确保在此连接字符串中指定的计算机上安装了SQL Server,并且该服务器可以访问。