MVC 4 SQL Server Express异常处于非活动状态几分钟

时间:2015-12-01 23:08:20

标签: sql-server asp.net-mvc-4 model-view-controller sqlexception

我是MVC的新手,所以我使用基本模板开始了我的项目。我使用SQL Server 2008 R2和现有的数据库来处理登录和注册(而不是使用SQL Server Express的EF)。

我已经进行了使用现有数据库所需的更改。 唯一的问题是,在我登录到Web应用程序并保持非活动状态几分钟并刷新管理页面后,我收到了SQL Server错误

  

SQLExpress数据库文件自动创建错误

请注意,注销后登录显示的管理页面没有例外。

即使我从另一个浏览器登录而另一个浏览器显示异常,ctrl + F5也不见了,就像登录重新创建连接一样。

  1. 为什么我会收到此异常
  2. 为什么SQLEXPRESS
  3. 请记住,SQL Server服务正在运行,因此不是问题。

    有什么想法吗?

    堆栈跟踪:

      

    [SqlException(0x80131904):建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)]

         

    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection,Action 1 wrapCloseInAction) +6573870
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717
    System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +6600312 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +219 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6602662 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6603203 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +942 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +816 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +61 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
    1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& connection)+953      System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource 1 retry, DbConnectionOptions userOptions) +6610951 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry)+233      System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)+278      System.Data.SqlClient.SqlConnection.Open()+239      System.Web.Management.SqlServices.GetSqlConnection(String server,String user,String password,Boolean trusted,String connectionString)+98

    >

      

    [HttpException(0x80004005):无法连接到SQL Server数据库。]

         

    System.Web.Management.SqlServices.GetSqlConnection(String server,String user,String password,Boolean trusted,String connectionString)+4570794      System.Web.Management.SqlServices.SetupApplicationServices(String server,String user,String password,Boolean trusted,String connectionString,String database,String dbFileName,SqlFeatures features,Boolean install)+229      System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName,String dataDir,String connectionString)+908

1 个答案:

答案 0 :(得分:0)

仔细检查它是否正在运行。当我在服务器之间切换时,我有这个。 其次确保连接字符串正确,没有拼写错误,服务器名称正确等等。

它必须是其中之一,连接字符串或服务未运行。重启机器是一种选择。

按Windows快捷键Win + R打开运行窗口,或以其他任何方式进入它 在下面的屏幕截图中输入服务。这将打开服务对话框。查找SQL Express Server并选择它。然后单击“开始”链接以启动服务器。正如第二次拍摄。

enter image description here

enter image description here