2

I recently started working at a company for whom I need to modify software to support connecting to our SQL Server database and connecting to a LocalDB instance. For testing purposes, I decided to use Windows Sandbox. I've also tried with a Hyper-V VM and additional "backup" PCs with similar results.

The program itself is a C# .NET Framework v4.6.1 application, installed using ClickOnce. The ClickOnce installer has a prerequisite for SQL Server 19 LocalDB which gets installed prior to the program running from the vendor's website. Upon launching the program, I select to connect to a local database, which is a code generated string, but the LocalDB fails to start. The connection string looks something like this due to being generated for Entity Framework 6 (formatted for readability):

metadata=res://*/DeadweightModel.csdl|res://*/DeadweightModel.ssdl|res://*/DeadweightModel.msl;
provider=System.Data.SqlClient;
provider connection string='
    Data Source=(LocalDB)\MSSQLLocalDB;
    AttachDbFilename="C:\ProgramData\Company Directory\database.mdf";
    Integrated Security=True;
    Pooling=False;
    MultipleActiveResultSets=True;
    Connect Timeout=30;
    Application Name=EntityFramework'

The connection ultimately just times out. Since I've been dealing with this branch for a few weeks on and off, I've learned to ignore the connection string for now and just focus on the LocalDB installation instead. In a fresh sandbox instance, I used the ClickOnce installer to install the LocalDB '19 version and attempted to start the default instance from PowerShell. Here are the results:

PS C:\Program Files\Microsoft SQL Server\150\Tools\Binn> .\SqlLocalDB.exe info
MSSQLLocalDB

PS C:\Program Files\Microsoft SQL Server\150\Tools\Binn> .\SqlLocalDB.exe create
Creation of LocalDB instance "MSSQLLocalDB" failed because of the following error:
Error occurred during LocalDB instance startup: SQL Server process failed to start.

PS C:\Program Files\Microsoft SQL Server\150\Tools\Binn> .\SqlLocalDB.exe create
LocalDB instance "MSSQLLocalDB" created with version 15.0.2000.5.

Something to notice here is that the first attempt to create the default instance fails, but subsequent attempts succeed.

PS C:\Program Files\Microsoft SQL Server\150\Tools\Binn> .\SqlLocalDB.exe start
Start of LocalDB instance "MSSQLLocalDB" failed because of the following error:
Error occurred during LocalDB instance startup: SQL Server process failed to start.

It doesn't matter how many times I attempt to start the instance, it just fails. Every failure here has a corresponding Windows Application logged event as follows:

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.

And the LocalDB log shows:

2021-07-01 09:38:47.19 spid14s     Starting up database 'mssqlsystemresource'.
2021-07-01 09:38:47.19 spid20s     Error: 17826, Severity: 18, State: 4.
2021-07-01 09:38:47.19 spid20s     Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.
2021-07-01 09:38:47.19 spid20s     Error: 17120, Severity: 16, State: 1.
2021-07-01 09:38:47.19 spid20s     SQL Server could not spawn FRunCommunicationsManager thread. Check the SQL Server error log and the operating system error log for information about possible related problems.

All of that being said, I've attempted to manually install LocalDB '16, '17, and '19 manually (through the SQL Server installer), all with similar results. I've tried doing these steps on a new Virtual Machine running Windows 10 Pro and a freshly restored Windows 10 Home PC with the same results. On our dev computers and our production computers, LocalDB works as expected. The issue is that this needs to work, out of the box, on a brand new, fresh install of Windows 10 and it doesn't. I'd also like to get it working in Sandbox for development purposes.

I have tried doing a full install of SQL Server Express in the Sandbox, which fails. Per some suggestions on SO, I've installed VC++ '15-19, which helped the manual installs actually install, but they still didn't start. I managed to get the LocalDB default instance to start a few times previously, but every time I managed to it was immediately stopped and I still couldn't connect to it.

Sorry for the long winded post, but I'm at my breaking point with troubleshooting this and all of the searching that I've done has ended with no changes. Please, any suggestions are welcome.

  • Just use SQL Express with tcpip enabled – ErikEJ Jul 01 '21 at 14:13
  • SQL Express installer fails in Sandbox as well. It's also complete overkill. The computers that will be running this will be air gapped PCs so they can't connect to a centralized DB unfortunately. – Volatile Pulse Jul 01 '21 at 14:39
  • SQL Server process fails, so it really has nothing to do with LocalDB, but rather with whole SQL Server. So what I could suggest - checking if SQL Service account has all required permissions- https://support.microsoft.com/en-us/topic/sql-server-services-using-domain-credentials-fail-to-start-1cbe142d-db6b-aaad-2684-0e46d4f6dbfa Or just set SQL Server processes run from LocalSystem account. Additionally you could check if port 1433 is free (cause i see some network-related error, so it might fail trying to occupy 1433 port) – Nikita Chayka Jul 01 '21 at 14:41
  • @NikitaChayka `netstat -a` shows that port 1433 isn't in use in the Sandbox or the host PC so I don't believe that is the issue. I'm also not familiar with how to configure service accounts with specific permissions. The included instructions weren't descriptive enough. I chose Sandbox due to ensuring a consistent environment every time, but this issue extends to VMs and physical machines. I looked through the services in Sandbox and the only SQL related one I saw was the `SQL Server VSS Writer` service. That struck me as odd, but I'm also grasping at straws here. – Volatile Pulse Jul 01 '21 at 15:20
  • Might be of little help but there is a Note in the page below saying: "The first time a user on a computer tries to connect to LocalDB, the automatic instance must be both created and started. The extra time for the instance to be created can cause the connection attempt to fail with a timeout message. When this happens, wait a few seconds to let the creation process complete, and then connect again." https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver16 – Only You Oct 28 '22 at 14:04
  • @OnlyYou while there are some known issues with the automatic instance being created, the documentation makes it sound like once it's created, it can be started and connected to. The last parts aren't happening. Unfortunately, I never found a fix for this. I had to resort to either using brand new (or reformatted) hardware or avoid modifying this section of the code. Sadly, I need this resolved as I am about to migrate other software from SQLite to SQL Server or similar and need a clean testing environment. – Volatile Pulse Nov 30 '22 at 21:15

0 Answers0