How can I stop one instance of SQL Server 2019 Express LocalDB?

I am developing a Windows program, using C# and VS 2022. This program is linked to a .mdf database file, and everything works fine in development.

The next step was to create an installer for it. I used a setup project template, where I added the .mdf, the executable, leaving the rest up to the wizard. As prerequisites, I chose .NET Framework 4.7.2 and SQL Server 2019 Express LocalDB. Also, I created a file, CustomInstaller.cs, with the following code:

using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Data.SqlClient;
using System.IO;

[RunInstaller(true)]
public class CustomInstaller : Installer
{
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        AttachDatabase();
    }

    private void AttachDatabase()
    {
        string targetDir = Context.Parameters["targetdir"];
        string dbFilePath = Path.Combine(targetDir, "Colibri.mdf");
        //string connectionString = @"Server=(localdb)MSSQLLocalDB;Integrated Security=True;";
        string connectionString = @"Data Source = (LocalDB)MSSQLLocalDB; Integrated Security = True; Connect Timeout = 30;";

        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();
            string sql = $"CREATE DATABASE Colibri ON (FILENAME = '{dbFilePath}') FOR ATTACH";
            using (SqlCommand command = new SqlCommand(sql, connection))
            {
                command.ExecuteNonQuery();
            }
        }
    }
}

When I first tested the installer, everything went fine, until I got the error message:

Unable to connect to SQL Server instance

then everything rolled back.

The problem is that, now, I cannot use the database functions from inside Visual Studio:

  1. I cannot access the .mdf file which I use for development. I cannot open it from the Server Explorer, because I get the following message:

    The attempt to attach to the database failed with the following information:
    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.

  2. I cannot connect to the server, from the SQL Server Object Explorer window, because I get the error message that the login failed for my user (error 18456), although I never tinkered with any login details.

  3. Reinstalled the entire Data Storage and Processing Toolset from the VS installer. Nothing.

  4. Installed SQL Server 2019 from Microsoft website. Nothing. Uninstalled it after.

Now, however, if I run the setup again, I get the following error message:

Error 1001. A network-related or instance-specific error occurred while establishing a connection to the SQL server (…). Error 50: Local Database Runtime error occurred…

If I change the name of the database from the above file, I get the following error message:

<new file name> could not be found

So, there is something controlling the server, but not me.

What did I do wrong? How can I fix this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật