如何将自定义桌面应用程序数据库安装到SQL Express? [英] How to install a custom desktop application database to SQL Express?

查看:175
本文介绍了如何将自定义桌面应用程序数据库安装到SQL Express?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用自定义数据库进行存储的WPF桌面应用程序。
我需要准备一个安装项目(从Visual Studio 2008)(完整安装,而不是ClickOnce)。



我可以添加到先决条件列表应用程序,它在安装应用程序期间安装。



我的问题是:在安装过程中如何运行脚本来创建应用程序需要的数据库?或者如何在设置过程中将数据库恢复到客户端机器?



另一个相关问题,如果客户端机器上已经存在会发生什么情况?如何检测实例名称和连接数据?然后如何改变实体框架连接到该数据库的连接字符串 - 如果需要 -



谢谢
Ed

解决方案

SQL Server Express Edition通常是本地数据库的一个非常糟糕的选择。这是一个服务器级引擎,喜欢使用大量资源并作为服务运行(即使您的应用程序未运行,它也会使用这些资源)。换句话说,它属于服务器。



我在桌面上使用的唯一的地方,几乎有意义的是作为 Microsoft Small Business Accounting 应用程序,在这种情况下,您通常将该程序安装在主要目的是为您的业务进行会计的机器上。 / p>

你应该做的是使用桌面或进程中的类引擎,如SQL Server 精简版,Sqlite,甚至Access。这也将大大简化您的部署。



如果您坚持使用此操作,请知道安装程序将创建一个新的sql实例系统上的服务器。 SQL Server会很好的。但是,您需要在应用程序的连接字符串中进行说明,这可能会更复杂一些。此外,要设置数据库,您有几个选项:




  • 在应用程序第一次启动时从客户端代码创建

  • 使用自定义安装程序创建它(由于msi权限而难以正确)

  • 分发预构建* .mdf文件,并附加自定义安装程序操作或在应用程序的第一次启动时。


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

解决方案

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.

这篇关于如何将自定义桌面应用程序数据库安装到SQL Express?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆