error to add mdf file in visual studio 2019

Skull Lim 1 Reputation point
2021-12-16T04:36:51.977+00:00

I was unable to add/ create SQL server database which is mdf file in visual studio 2019. It shows me the error message as below:
158046-wapp16.png

Here is the step I perform:
First, I right click on app data folder > add > new item > select SQL server database > add.
158028-wapp17.png

After click add it shows me the error message and I stuck at this step. Can I have the solution?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,327 questions
{count} votes

5 answers

Sort by: Most helpful
  1. CathyJi-MSFT 21,121 Reputation points Microsoft Vendor
    2021-12-16T06:21:36.53+00:00

    Hi @Skull Lim ,

    >Error occurred during LocalDB instance startup: SQL server process failed to start.

    It seems the SQL server instance stopped that you want to connected. Please check if your SQL server instance is stopped from SQL server configuration manager as below screenshot. If the state of SQL server service is stopped, please start the SQL server service. If this is a Local DB instance, please check the solution offered by Olaf.
    158095-screenshot-2021-12-16-142046.jpg

    If you have any confuse, please let me know.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  2. Olaf Helper 39,181 Reputation points
    2021-12-16T06:40:21.74+00:00

    Error occurred during LocalDB instance startup: SQL server process failed to start

    The error message stats LocalDB and that's the default SQL instance is utilizing; not a full featured SQL Server.
    Use SqlLocalDB Utility to start an instance of LocalDB and try it again.


  3. CathyJi-MSFT 21,121 Reputation points Microsoft Vendor
    2021-12-20T06:20:54.647+00:00

    Hi @Skull Lim ,

    Please using below cmd command to check Local DB information.

    C:\> SqlLocalDb info MSSQLLocalDB  
    

    Create a instance for Local DB.

    C:\> SqlLocalDb create "MyInstance"  
    

    Check the information of Local DB instance that your created.

    C:\> SqlLocalDb info "MyInstance"  
    

    Start Local DB instance

    SqllocalDB.exe s  MyInstance  
    

    Check the state of Local DB instance.

    C:\> SqlLocalDb info MSSQLLocalDB  
    

    When all else fails and you don't care about data loss, delete and recreate your Local DB instance! At the command prompt

    C:\> SqlLocalDb delete "MyInstance"  
    C:\> SqlLocalDb create "MyInstance"  
    

    Below is a test in my environment.
    158895-screenshot-2021-12-20-142254.jpg
    158913-screenshot-2021-12-20-142328.jpg
    158914-screenshot-2021-12-20-142450.jpg
    158921-screenshot-2021-12-20-142531.jpg

    Refer to this blog Getting Started with SQL Server LocalDB.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  4. CathyJi-MSFT 21,121 Reputation points Microsoft Vendor
    2022-01-10T07:09:19.393+00:00

    Hi @Skull Lim ,

    Sorry for reply late.

    You can use below Powershell commands to set the LocalDB 1800 trace flag.

    New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15E.LOCALDB\MSSQLServer\Parameters' -Force  
    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15E.LOCALDB\MSSQLServer\Parameters' -Name 'SQLArg0' -Value "-T1800" -PropertyType String –Force  
    

    Then start the Local DB again.

    Refer to this similar thread to get detail information.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  5. CathyJi-MSFT 21,121 Reputation points Microsoft Vendor
    2022-01-11T06:23:24.49+00:00

    Hi @Skull Lim ,

    To resolve this issue, we can also add a registry key which will cause the behavior of Windows 11 and later to be similar to Windows 10. This will force the sector size to be emulated as 4 KB in size. To add the ForcedPhysicalSectorSizeInBytes registry key, use the Registry Editor, or you can run one of the following commands in Windows command prompt or PowerShell, executed as an administrator.

    Registry Editor

    1.Navigate to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\stornvme\Parameters\Device.
    2.On the Edit menu, point to New, and then select Multi-String value. Name it ForcedPhysicalSectorSizeInBytes.
    3.Modify the new value, type in 4095. Click OK and close the Registry editor.

    Command Prompt as Administrator

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

    PowerShell as Administrator

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\stornvme\Parameters\Device" -Name   "ForcedPhysicalSectorSizeInBytes" -PropertyType MultiString -Force -Value "* 4095"  
    

    Please refer to MS document Troubleshoot errors related to system disk sector size greater than 4 KB to get more detail information.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".