SQLLocalDB 未启动

Kau*_*hik 7 sql-server localdb

SQLLocalDB 无法启动并抛出如下错误。

**C:\Windows\system32>sqllocaldb c MSSQLLocalDB**

Creation of LocalDB instance "MSSQLLocalDB" failed because of the following error:
Error occurred during LocalDB instance startup: SQL Server process failed to start.

***Note:*** Command started with Run as Administrator. 
Run Code Online (Sandbox Code Playgroud)

事件查看器显示以下日志:

Windows API call WaitForMultipleObjects returned error code: 575. Windows system error message is: {Application Error}
The application was unable to start correctly (0x%lx). Click OK to close the application.
Reported at line: 3714. 

Source: SQLLocalDB 15.0
Event ID: 528
Level: Error
Run Code Online (Sandbox Code Playgroud)

操作系统: Windows 11 Pro build 22000.832

安装的版本: Microsoft SQL Server 2019 (15.0.4153.1)


从 Visual Studio 2022 版本 17.2.6 连接 SQLLocalDB 时,显示以下消息:

TITLE: Error

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 to start.
) (Microsoft SQL Server, Error: -1983577846)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=-1983577846&LinkId=20476

------------------------------
Error Number: -1983577846 
Severity: 20 
State: 0 
Run Code Online (Sandbox Code Playgroud)

以下是文件 <error.log> 的详细信息:

2022-07-28 12:13:11.50 Server      Microsoft SQL Server 2019 (RTM-CU12) (KB5004524) - 15.0.4153.1 (X64) 
    Jul 19 2021 15:37:34 
    Copyright (C) 2019 Microsoft Corporation
    Express Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 22000: )

2022-07-28 12:13:11.50 Server      UTC adjustment: 5:30
2022-07-28 12:13:11.50 Server      (c) Microsoft Corporation.
2022-07-28 12:13:11.50 Server      All rights reserved.
2022-07-28 12:13:11.50 Server      Server process ID is 10072.
2022-07-28 12:13:11.50 Server      System Manufacturer: 'LENOVO', System Model: '82KB'.
2022-07-28 12:13:11.50 Server      Authentication mode is MIXED.
2022-07-28 12:13:11.50 Server      Logging SQL Server messages in file 'C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\error.log'.
2022-07-28 12:13:11.50 Server      The service account is '<domain\user>'. This is an informational message; no user action is required.
2022-07-28 12:13:11.50 Server      Command Line Startup Parameters:
     -c
     -S "MSSQL15E.LOCALDB"
     -s "LOCALDB#C0C8C320"
     -d "C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\master.mdf"
     -l "C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\mastlog.ldf"
     -e "C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\error.log"
2022-07-28 12:13:11.51 Server      SQL Server detected 1 sockets with 4 cores per socket and 8 logical processors per socket, 8 total logical processors; using 8 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2022-07-28 12:13:11.51 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2022-07-28 12:13:11.51 Server      Detected 16183 MB of RAM. This is an informational message; no user action is required.
2022-07-28 12:13:11.51 Server      Using conventional memory in the memory manager.
2022-07-28 12:13:11.51 Server      Page exclusion bitmap is enabled.
2022-07-28 12:13:11.64 Server      Buffer Pool: Allocating 2097152 bytes for 1740277 hashPages.
2022-07-28 12:13:11.66 Server      Default collation: SQL_Latin1_General_CP1_CI_AS (us_english 1033)
2022-07-28 12:13:11.67 Server      Buffer pool extension is already disabled. No action is necessary.
2022-07-28 12:13:11.70 Server      Query Store settings initialized with enabled = 1, 
2022-07-28 12:13:11.70 Server      The maximum number of dedicated administrator connections for this instance is '1'
2022-07-28 12:13:11.70 Server      Node configuration: node 0: CPU mask: 0x00000000000000ff:0 Active CPU mask: 0x00000000000000ff:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2022-07-28 12:13:11.70 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2022-07-28 12:13:11.71 Server      In-Memory OLTP initialized on standard machine.
2022-07-28 12:13:11.71 Server      [INFO] Created Extended Events session 'hkenginexesession'
2022-07-28 12:13:11.71 Server      Database Instant File Initialization: disabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
2022-07-28 12:13:11.72 Server      Total Log Writer threads: 2. This is an informational message; no user action is required.
2022-07-28 12:13:11.73 Server      clwb is selected for pmem flush operation.
2022-07-28 12:13:11.73 Server      Software Usage Metrics is disabled.
2022-07-28 12:13:11.74 spid9s      Starting up database 'master'.
2022-07-28 12:13:11.75 spid9s      There have been 256 misaligned log IOs which required falling back to synchronous IO.  The current IO is on file C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\master.mdf.
Run Code Online (Sandbox Code Playgroud)

到目前为止的尝试: 我尝试删除SSIS、VS、注册表项、文件夹等。即使我再次安装干净的Windows 11,以避免卸载后残留文件/注册表的问题。

我的域帐户已在此计算机上的管理员组中。但我还另外添加到了 sysadmin 中。MDF 文件所在的文件夹已具有足够的权限。

Dav*_*e B 12

我的设置和问题与您在 Localdb 实例上列出的相同,包括相同的 SQL Server 错误日志。

Microsoft 文档中的以下故障排除文章提供了修复程序。

https://learn.microsoft.com/en-us/troubleshoot/sql/admin/troubleshoot-os-4kb-disk-sector-size

您发布的错误日志中列出的错误消息在文章的“场景 #2”中进行了描述。

2021-11-05 23:42:47.14 spid9s 有 256 个未对齐的日志 IO,需要回退到同步 IO。当前 IO 位于文件 C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\master.mdf 上。

来自文章的原因部分:

在服务启动期间,SQL Server 开始数据库恢复过程以确保数据库一致性。此数据库恢复过程的一部分涉及在尝试打开系统和用户数据库文件的活动之前对底层文件系统进行一致性检查。

在运行 Windows 11 的系统上,一些新的存储设备和设备驱动程序将公开大于支持的 4 KB 扇区大小的磁盘扇区大小。

发生这种情况时,SQL Server 将因文件系统不受支持而无法启动,因为 SQL Server 目前支持的扇区存储大小为 512 字节和 4 KB。

故障排除文章的解决方案部分指出:

Microsoft 目前正在调查此问题。考虑以下解决方案之一:

我使用了以下步骤并解决了该问题:

您可以添加一个注册表项,这将使 Windows 11 及更高版本的行为与 Windows 10 类似。这将强制将扇区大小模拟为 4 KB。要添加 ForcedPhysicalSectorSizeInBytes 注册表项,请使用注册表编辑器,或者您可以在 Windows 命令提示符或 PowerShell 中运行以下命令之一(以管理员身份执行)。

  1. 以管理员身份启动命令提示符

  2. 通过在命令提示符中输入以下命令将密钥添加到 Windows 注册表:

    REG ADD“HKLM\SYSTEM\CurrentControlSet\Services\stornvme\Parameters\Device”/v“ForcedPhysicalSectorSizeInBytes”/t REG_MULTI_SZ /d“* 4095”/f

完成注册表项后重新启动计算机。我必须删除现有的 mssqllocaldb 并在重新启动计算机后重新创建它。以管理员身份从命令提示符

Sqllocaldb delete mssqllocaldb

Sqllocaldb create mssqllocaldb -s
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

链接也描述了与故障排除文章相同的问题。我在使用新的三星笔记本电脑时遇到了 SQL Server 启动失败的问题。