SQL Server Local DB 2023年春季稳定性问题技术求助
问题背景
我们有一款基于WPF .NET的桌面应用,使用SQL Server Local DB作为数据库,已发布约6年,部署在数百台计算机上。2023年春季开始出现多处数据库稳定性问题,2022年运行一切正常。由于80%的应用使用量集中在春季,可能2022年秋季已出现问题但未被发现。软件唯一的变更为从ADO切换至显式拼接SQL语句,问题在Windows 10和Windows 11设备上均有出现。
应用可能运行数小时甚至数天无异常,突然遭遇数据库不稳定;有时甚至无法启动,需重启计算机才能连接数据库。问题出现随机,部分安装实例从未出现问题,部分则频繁报错。
已尝试的解决方案
- 将每次通信新建连接改为读取使用静态连接、事务使用实例连接,缓解了大部分问题,但未彻底解决;
- 当语句执行失败时,添加逻辑终止SQL Server实例并手动重建,再重试语句,该“二次尝试”解决了更多问题,但日志中有时会出现大量SQL Server实例重启记录;
- 原安装SQL Server 2016,开始升级用户至SQL Server 2022,有一定改善;
- 为所有需要数据库连接的调用者添加“连接测试”,执行
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;确认连接是否可用,若不可用则执行方案2的逻辑。
启动时常见错误
第一类更为频繁:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=12085; handshake=0; at System.Data.ProviderBase.DbConnectionpool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultileObjectTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 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 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed or start.) at System.Data.ProviderBase.DbConnectionpool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultileObjectTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
运行时常见错误
前两类最为频繁,其他偶尔出现:
The wait operation timed out. Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) ExecuteReader requires an open and available Connection. The connection's current state is open. at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method) The ConnectionString property has not been initialized. at System.Data.SqlClient.SqlConnection.PermissionDemand()
恳请各位提供解决方案或思路。
内容的提问来源于stack exchange,提问作者adamjhilton
相关产品推荐
相关产品推荐

