2014-01-29 25 views
0

我剛剛在VS2010中提出了一個新的ASP.net MVC4互聯網應用程序。雖然點擊註冊登錄鏈接,瀏覽器通過例外(請參閱下文)。我沒有在代碼中做任何修改。我有新的安裝Vislual Studio Professional 2010。在以前的安裝中,一切正常。TargetInvocationException引發mvc4互聯網默認應用程序

的例外是在代碼

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

看來,你沒有運行SQL數據庫實例。檢查web.config中的連接字符串,並確保在此連接字符串中指定的計算機上安裝了SQL Server,並且該服務器可以訪問。

+0

我在我的機器上有SQL服務器管理工​​作室,我可以看到本地(點)可以在那裏訪問。連接字符串在web.config中也有,

+0

確保您有本地運行的SQLExpress實例。 –

+0

如何檢查?請描述,我是網絡開發新手。 –

相關問題