How to deploy the "SQL Server Express + EF" application
This is my first time to deploy an application that uses a SQL Server Express database. I am using Entity Framework Model First contact the database. and I created an install wizard using Install Shield to install the app.
These are the steps I took to install the application on the target computer:
- Installing MS SQL Server Express (DEST)
- Installing the program using the setup file (DEST)
- Detach the database from the SQL server and copy the corresponding .mdf, .ldf file to the destination computer.
- Attach the database file on the destination computer using SQL Server Management Studio.
I know the server names and the SQL name. The instances are different and my program may not work correctly with the old connection string.
I am starting on this and I want to know what to do on the target computer to run the program?
- Should I find a way to change the connection string at runtime ?!
- or is there a way to change the installshield project and it does this work for me? (installshield - professional edition)
- Could you suggest me what to do?
In my search, I've seen WiX can do this, but I find it difficult and I don't have enough time to learn it. I need to deploy my application as soon as possible.
Thank you so much.
source to share
Some tips for using LocalDB in your project:
Download SQL Express LocalDB 2014 here . You can install it without pauses with a single command such as
msiexec /i SqlLocalDB.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
Include your .MDF in your VS project and set the properties to a value
Copy if newer
so it gets copied to your bin folder at build time so that it is automatically included in the installer.
In your application (s
), check if the database file exists in the desired location (for example
) ( WPF Desktop Application with MDF used locally for all local users ). If not, copy the .mdf file from the application installation directory to the data directory.
so that your connection string looks like this:
<add name="MyContextLocalDB" connectionString="Server=(localdb)\MSSQLLocalDB; Integrated Security=True; AttachDBFilename=|DataDirectory|\MyDatabase.mdf; Connection Timeout = 30" providerName="System.Data.SqlClient" />
The connection timeout needs to be increased as LocalDB exe starts up when you first try to connect to it.
You can also use Database.CreateIfNotExists , but I have never tried it.
source to share