Search code examples
c#sql-serverwpfpublish

Installing a C# WPF application with local SQL Server database on another PC


I have a question that I have developed a C# WPF application which requires a local SQL Server database. I am having trouble publishing the application to a different computer where there is no SQL Server installed.

Is it necessary for me to have a SQL Server installed on all the PCs where I am going to install my application? Or am I missing something?

I am making the setup file form Advance Installer and copying the .mdf database to the location mentioned in the connection string

string connectionString = @"Data Source =(LocalDB)\MSSQLLocalDB; AttachDbFilename = " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\abc\Databases\abc.mdf; Integrated Security = True; Connect Timeout = 30";

The error I am getting:

error message

If having a SQL Server a necessity, which one should I install on a low end pc? any help will be appreciated. Thank you


Solution

  • If you want to use a .mdf file, then you must have SQL Server installed

    • either locally on each PC
    • or centrally on a server which all the PC's can connect to

    If you install a .mdf file locally on a PC and you want to use the AttachDbFileName= parameter in your connection string, then you must install SQL Server Express on each PC that has this application. Other editions of SQL Server do NOT support the AttachDbFileName= approach.