【问题标题】:MVC 4 SQL Server Express exception after being inactive for a few minutes处于非活动状态几分钟后的 MVC 4 SQL Server Express 异常
【发布时间】:2015-12-01 23:08:20
【问题描述】:

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

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

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

请注意,注销并登录后显示的管理页面没有异常。

即使我从其他浏览器登录,而另一个浏览器显示异常,按 ctrl + F5 并且异常消失了,就像登录重新创建连接一样。

  1. 为什么会出现此异常
  2. 为什么是SQLEXPRESS

请记住,SQL Server 服务正在运行,所以这不是问题。

有什么想法吗?

堆栈跟踪:

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

System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常, Boolean breakConnection, Action1 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& 连接) +953 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +6610951 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) +233 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 重试) +278 System.Data.SqlClient.SqlConnection.Open() +239 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trust, String connectionString) +98

>

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

System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trust, String connectionString) +4570794 System.Web.Management.SqlServices.SetupApplicationServices(字符串服务器、字符串用户、字符串密码、布尔可信、字符串连接字符串、字符串数据库、字符串 dbFileName、SqlFeatures 功能、布尔安装)+229 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +908

【问题讨论】:

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


    【解决方案1】:

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

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

    按windows快捷键Win+R打开运行窗口,或任何其他方法可以打开它 在下面的屏幕截图中输入服务。这将打开服务对话框。查找 SQL Express Server 并选择它。然后单击开始链接以启动服务器。就像第二个屏幕截图一样。

    【讨论】:

    • 再次检查了兄弟...我已经停止、暂停、重新启动链接...它正在运行
    猜你喜欢
    • 2020-06-25
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    相关资源
    最近更新 更多