1

I have a WPF application where I use Entity Framework for interacting with the database that is on SQL Server Express on my machine. I'm reasoning on small projects where data will not be huge and then I don't want to install SQL Server Express on client's machine for two reasons:

  1. installation takes a long time
  2. these projects must be executable on computers with low hardware specs (installation of SQL Server takes too much time)

I tried installing LocalDB on client machine, created default instance and started

The problems are two:

  1. how to reconfigure app.config file making Entity Framework connecting to database? (in development environment connection string is SQL Server style)

  2. where to put database files? (user's profile root?)

Am I following the correct way? I know only two way to do this, installing SQL Server Express or using LocalDB the may be a third way?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
David
  • 73
  • 5
  • 14
  • `LocalDB` ***IS*** SQL Server Express - just a special developer-oriented version of it that is **not** intended for production use – marc_s Sep 18 '15 at 15:59
  • sorry @marc_s for the small delay in my delay to reply to you, i've seen a lot of SQL Server Express installed in production, we talk about small applications where the cost of SQL Server Standard is impossible to accept – David Oct 19 '20 at 16:35
  • Yes- the **full**, server-based SQL Server Express which by default is the `SQLEXPRESS` instance - that's fine (as long as your database stays below 10 GB) - but the SQL Server Express **LocalDB** edition is really designed for developer use only – marc_s Oct 19 '20 at 16:48

1 Answers1

1

You can set up your app.config file as follows (just replace "C:\Database.mdf" with the full path to your database):

  <connectionStrings>
     <add name="NameOfConnectionString" connectionString="data source=(LocalDB)\v11.0;attachdbfilename=C:\Database.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
   </connectionStrings>

But with this you will end up having always the same static connection string.

Perhaps you want to store you database rather in some user folder. This will get a sub folder of the users documents folder at runtime:

string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MyAppsFolder");

If you want to deploy the local db to the users machine, you might want to create a installer project for this. See here


The alternative would be to install some version of SQL-Server on the client machine.

If it is possible that one the client site you will have more than one concurrent user you will have no other choice.


Difference between local db and SQL-Server express

If you need more information on the usage scenarios of local db and SQL-Server express, check out this question and answers.

This MSDN Site has also a bunch of information on LocalDB.

Community
  • 1
  • 1
Martin
  • 5,165
  • 1
  • 37
  • 50