Skip to content
www.mytechnote.ru
Menu
  • Administration
    • Scripts
  • Equipment
    • Reviews
    • Instructions
  • Other
  • English
    • English
    • Русский
Menu

How to Fix Microsoft SQL Server Error 5178 with Virtual Hard Drive

Hello to all database enthusiasts! Today, we dive into a prevalent issue many face with Microsoft SQL Server – the notorious Error: 5178. If you’ve seen this error:

Error: 5178, Severity: 16, State: 1.
Cannot use file ‘c:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\master.mdf’ because it was originally formatted with sector size 4096 and is now on a volume with sector size 3072. Move the file to a volume with a sector size that is the same as or smaller than the original sector size.

You’ll understand the struggle. But fear not! This blog will guide you step-by-step to resolve this Microsoft SQL Server error using a virtual hard drive technique.

Why Does This SQL Server Error Happen?

In simple terms, the server can’t start because there’s a mismatch in sector sizes. An old hard drive, among other reasons, can be the culprit. Thankfully, you can fix this without a system reinstall.

The Virtual Hard Drive Solution for SQL Server

1. Locate the Affected Folder:

First, access the MSSQL folder of your SQL Server instance (e.g., c:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL). Rename the DATA directory to DATA.old.

2. Virtual Hard Drive Creation:

Open Control Panel → Administrative Tools → Computer Management. In Disk Management, initiate the creation of a virtual hard drive.

Computer management console, disks management tab

3. Size & Location:

Allocate sufficient space for your databases on this new drive.

Create new VHD wizzard, set path and size

4. Initialization & Formatting:

Initialize the new disk and format it, setting the cluster size to 4096 bytes.

Initializing disk

Creating simple volume

5. Mount volume:

Mount your drive as emtpy NTFS folder and set sector size to 4096.

Set mount point

Format drive and set cluster size

5. Transfer Data:

Shift all content from DATA.old to your new DATA directory.

6. Setting Permissions:

Proper file permissions are vital. Use the command line to check and grant full access to the user NT SERVICE\MSSQL$InstanceName for all files within the DATA directory.

To check original permissions:

icacls DATA.old\*

Checkout permissions

To set them use:

icacls DATA\* /grant «NT SERVICE\MSSQL$SQLEXPRESS»:F

7. Automate on Startup:

Check if MSSQL service now can be started without issues. If so, to ensure smooth operations upon system start, create and schedule a task to mount the virtual disk and start the SQL Server. To do it create a file attach.txt:

select vdisk file=”C:\vhds\mssql.vhd”
attach vdisk

And start-sql.bat:

diskpart /s "C:\vhds\attach.txt"
ping -n 10 127.0.0.1
net start mssql$instanceName

Don’t forget to change mssql$instanceName to your’s, for example to mssql$sqlexpress.

Add created script to Task Scheduller.

Creating new task in task shceduller, seting name

Creating new task in task shceduller, setting tirgger startup type

Creating new task in task shceduller, selecting script

Creating new task in task shceduller, conditions tab

Finally, restart your computer. If everything’s set up correctly, MSSQL should initiate seamlessly!

Wrapping Up

This virtual hard drive solution can save the day for many Microsoft SQL Server users. It’s one of the many ways we can troubleshoot and optimize our databases. If you found this guide helpful, don’t forget to share and comment!

 

Posted on 08.10.201730.05.2024 by sanglyb

Post navigation

← How to Set Up an OpenVPN Server on Mikrotik: A Comprehensive Guide
How to Watch Videos Directly in the SSH Console Using Mplayer →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Подписывайтесь

Youtube
vk
telegram
github
twitter
rss
  • Форум
  • Об авторе
  • Поддержать автора

Популярные записи

Новые записи

  • How to Extend an LVM Partition in Linux
  • SCCM Reporting Errors After Migrating from SQL Server 2016 to 2019
  • Problem Using PassFiltEx on Older CPUs
  • How to remove attachments from old calendar events in Exchange using a script
  • How to download and install Office 2024 LTSC

Архивы

  • 2026 (3)
  • 2025 (5)
  • 2024 (7)
  • 2023 (30)
  • 2022 (4)
  • 2020 (17)
  • 2017 (82)
  • 2016 (5)
© 2015-2026 www.mytechnote.ru
Использование материалов сайта возможно только с разрешения владельца или обязательна индексируемая, прямая, передающая вес ссылка на материал.