Reputation: 69
I am building a WPF application that connects to a SQL Server database. I am wondering how I should go about, deploying the application on the client's computers together with the local database.
My initial thoughts are (assuming that the client computers have SQL Server installed):
.exe
file of the applicationIs there a better way of doing this? I could create a service inside the application that sets some sort of boolean value in the registry of the computer and runs the "init-database-scripts" only the first time but it feels wrong.
Any other suggestions?
Thank you!
Upvotes: 2
Views: 514
Reputation: 199
Add a SQL Server database project to your Visual Studio solution. When you build the project, a Dacpac file is created which can be installed on a client machine using SQLPackage.exe. Basically, your app installation script/software calls SQLPackage along with your Dacpac file to install/update the SQL database. Here is a link to a tutorial on setting up a SQL database project: Tutorial
Upvotes: 1
Reputation: 61339
First off, I would strongly consider making an actual installer using a tool like WiX. It can run the script for you at install time so you don't have to deal with the registry and such.
There is another option assuming you are using Entity Framework - Code First; you can use a database initializer to create your database. If you never think your model will change DropCreateDatabaseIfModelChanges
will work, otherwise enable migrations and use a migration initializer.
To use the initializer you picked, make sure to call Database.SetInitializer
in your applications startup routine.
Upvotes: 1