Global.asax中的用户代码未对Entity Exception进行处理

时间:2013-04-05 14:18:49

标签: global-asax redirect-loop

我首先在实体框架代码中使用Microsoft示例项目;“WingtipToys”。我所做的就是提取文件并打开解决方案。该项目已成功构建,但运行网站时出错。它在Global.asax中停在一行,消息为:实体异常未被用户代码处理基础提供程序在打开时失败”。令人惊讶的是,我几天前使用了这个示例项目并且它工作正常但突然发生了这个错误,即使我没有更改代码中的任何内容,现在即使使用新下载的副本我也会遇到同样的问题。

顺便说一句,当我通过谷歌浏览器浏览任何网页时,我收到此错误消息。 “此网页有重定向循环 http://“Serveraddress”/ErrorPage.aspx?handler=customErrors%20section%20-%20Web.config的网页导致了太多的重定向。清除此站点的cookie或允许第三方cookie可以解决问题。如果没有,则可能是服务器配置问题,而不是计算机问题。“

public class Global:HttpApplication     {         void Application_Start(object sender,EventArgs e)         {             //在应用程序启动时运行的代码             BundleConfig.RegisterBundles(BundleTable.Bundles);             AuthConfig.RegisterOpenAuth();             Database.SetInitializer(new ProductDatabaseInitializer());

        // Add Administrator.
        if (!Roles.RoleExists("Administrator")) --- !!!!!!!!!!!!!!!!!!!!!!!!!!Error at this line
        {
            Roles.CreateRole("Administrator");
        }
        if (Membership.GetUser("Admin") == null)
        {
            Membership.CreateUser("Admin", "Pa$$word", "Admin@contoso.com");
            Roles.AddUserToRole("Admin", "Administrator"); 

及以下是例外细节        的HResult = -2146232060        Message =无法打开登录请求的数据库“aspnet-WingtipToys”。登录失败。 用户'Jinx-PC \ Jinx'登录失败。        Source = .Net SqlClient数据提供程序        错误码= -2146232060        类= 11        LineNumber上= 65536        数= 4060        过程=“”        服务器=(的LocalDB)\ V11.0        状态= 1        堆栈跟踪:             在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& connection)             在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1重试,DbConnectionOptions userOptions,DbConnectionInternal& connection)             在System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1重试)             在System.Data.SqlClient.SqlConnection.Open()             at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition,DbConnection storeConnectionToOpen,DbConnection originalConnection,String exceptionCode,String attemptsOperation,Boolean& closeStoreConnectionOnFailure)        的InnerException:

0 个答案:

没有答案