How to install a custom desktop application database to SQL Express?

隐身守侯 提交于 2019-12-12 19:34:56

问题


I have a WPF desktop application that uses a custom database for storage. I need to prepare a setup project (from Visual studio 2008) (full setup, not ClickOnce).

I can add the to the list of prerequisites to the application and it does install during the setup of the application.

My question is: How can I run a script during the setup to create the database that the application needs? OR how can I restore the database to the client machine during the setup?

Another related question, what would happen if already exists on the client machine? How to detect the instance name and connection data? And then how to be able -if needed- to change the Connection string used by Entity framework to connect to that database?

Thanks, Ed


回答1:


SQL Server Express Edition is generally a really poor choice for a local database. It's a server-class engine that likes to use a lot of resources and runs as a service (so it's using up those resources even when your app isn't running). In other words, it belongs on a server.

The only place I've seen SQL Server Express used on a desktop that almost makes sense is as part of the Microsoft Small Business Accounting app, and in this case you generally install that program on a machine who's primary purpose is doing the accounting for your business.

What you should do is use a desktop or in-process class engine like SQL Server Compact Edition, Sqlite, or even Access. This will also greatly simplify your deployment.

If you insist on pushing through with this, know that the installer will create a new instance of sql server on the system. SQL Server will be fine with this. However, you'll need to account for that in the connection string of your app, and that can be a little more complicated. Additionally, to set up the database you have a couple options:

  • Create it from client code on first start of the app
  • Create it with a custom installer action (hard to get right because msi permissions)
  • Distribute an pre-build *.mdf file and attach with custom installer action or on first start of the app.


来源:https://stackoverflow.com/questions/978146/how-to-install-a-custom-desktop-application-database-to-sql-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!