Service-based Database run time error / Local DB instance does not exist or not accessible

313 Views Asked by At

I've recently built an app that makes use of the service-based database to store its data because the binding seems easy for a beginner.

Everything worked well in debug, but this error appears when I published it using the "click once install" publish option. Please note that I used the wizard and not the "Publish now" option, so the manifest is correct.

I've also checked in the prerequisites to install .Net Framework 4.8 & SQL Server Express Local DB 2012 before installing the app, and the installation also worked fine. I could see the SQL Server Running in task manager.

Publish settings:

Publish settings

SQL Server Running:

SQL Server Running

Here is the app.config code

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="Redo_V3.Properties.Settings.CNv3" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\RedoV3Database.mdf;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
</configuration>

Here is the error message

Please note that I've tested this app initially on a PC, and then on a VM in Virtual Box

Is there something wrong with my connection string? Or what could be the cause of this?

2

There are 2 best solutions below

0
On

I think I found out why it wouldn't run on another machine.

  1. Connection String is "static / absolute". It's pointing to an instance of the local DB server that only exists on my PC. So in order for this to work, an instance with the same name has to be created after installing sql server, even if the database file is correctly located. If the instance is not the same name, it won't be able to run
  2. After installation of the SQL Express Server local DB, no instance was automatically created. So I had to manually create an instance with the exact same name as written in the connection string, or else it won't work.
  3. This service-based database was created using SQL server 2016, whereas in the prerequisits of the installation wizard, only SQL Server + SQL Server express local DB 2012 are supported => I got another error saying the downgrade is not possible, because the database file was created with a newer version. So this app will only work on machines with SQL server 2016 installed.

My next obstable is, how do I make windows auto start an instance with that exact same name right after finishing installing SQL server?

1
On

Your connectionstrings points to wrong database , try to find suitable connectionstring from https://www.connectionstrings.com/