It's my first time to Deploy an Application which uses SQL Server Express Database. I'm Using Entity Framework Model First to contact Database. and i created a Setup wizard with Install Shield to Install the App.
These are Steps that I'v done to Install The Application in Destination Computer :
I know server names and SQL name Instances are different and my program can't run correctly with the Old Connection String.
I'm Beginner at this, and I want to know what should I do in the Destination Computer to make the program run?
in my searches I saw that WiX can do this, but I find it complicated, and i don't have enough time to learn it. i need to deploy the app ASAP.
Thanks alot.
Few hints for using LocalDB in your project:
Download SQL Express LocalDB 2014 here. You can install it silently with single command like this
msiexec /i SqlLocalDB.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
Include your .MDF in your VS project and set in properties to Copy if newer
so that it gets copied to your bin folder during build so that it is automatically included in the installer.
At your app startup (in app.cs
) check, if database file exists in desired location (e.g. %PUBLIC%\YourApp\Data
) (WPF Desktop Application with MDF used locally for all local users). If not, copy the .mdf file from your app install dir to your data dir.
Modify app.config
so that your connection string looks like:
<add name="MyContextLocalDB" connectionString="Server=(localdb)\MSSQLLocalDB; Integrated Security=True; AttachDBFilename=|DataDirectory|\MyDatabase.mdf; Connection Timeout = 30" providerName="System.Data.SqlClient" />
Connection timeout should be increased, since LocalDB exe is launched when you first try to connect to it.
You can also use Database.CreateIfNotExists, but I have never tried it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With