如何部署“ SQL Server Express + EF”;应用 [英] How to Deploy "SQL Server Express + EF" Application

查看:117
本文介绍了如何部署“ SQL Server Express + EF”;应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次部署使用SQL Server Express数据库的应用程序。
我首先使用实体​​框架模型与数据库联系。
和我用Install Shield创建了一个安装向导来安装该应用程序。

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 :


  1. 安装MS SQL Server Express(DEST)

  2. 使用安装文件(DEST)安装程序

  3. 从SQL Server删除数据库并进行复制.mdf,.ldf文件到目标计算机。

  4. 使用SQL Server Management Studio在目标计算机中附加数据库文件。

  1. Installing MS SQL Server Express (DEST)
  2. Installing The Program using Setup file (DEST)
  3. Detach Database from SQL server and Copy Related .mdf ,.ldf file to the Destination Computer.
  4. Attach database file in destination computer using SQL Server Management Studio.

我知道服务器名称和SQL名称实例不同,并且我的程序无法使用旧的连接字符串正确运行。

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?


  • 我应该找到一种方法更改运行时的连接字符串吗?!

  • 还是有什么方法可以修改installshield项目,它对我有用吗? (installshield是专业版)

  • 您能建议我做什么吗?

搜索我发现WiX可以做到这一点,但是我发现它很复杂,而且我没有足够的时间来学习它。我需要尽快部署应用。

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.

非常感谢。

推荐答案

在您的项目中使用LocalDB的一些提示:

Few hints for using LocalDB in your project:


  1. 下载SQL Express LocalDB 2014 此处。您可以使用这样的单个命令静默安装它

  1. Download SQL Express LocalDB 2014 here. You can install it silently with single command like this

msiexec / i SqlLocalDB.msi / qn IACCEPTSQLLOCALDBLICENSETERMS = YES

在VS项目中包含.MDF,并将属性设置为如果较新则复制,以便获取复制到构建过程中的bin文件夹中,以便自动将其包含在安装程序中。

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.

在应用启动时(在 app.cs中) )检查数据库文件是否位于所需位置(例如%PUBLIC%\YourApp\Data )(带有MDF的WPF桌面应用程序在本地用于所有本地用户)。如果不是,请将.mdf文件从应用程序安装目录复制到数据目录。

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.

修改 app.config ,以便您的连接字符串如下所示:
< add name = MyContextLocalDB connectionString = Server =(localdb)\MSSQLLocalDB; Integrated Security = True; AttachDBFilename = | DataDirectory | \MyDatabase.mdf;连接超时= 30 providerName = System.Data.SqlClient />

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.

您还可以使用数据库.CreateIfNotExists ,但我从未尝试过。

You can also use Database.CreateIfNotExists, but I have never tried it.

这篇关于如何部署“ SQL Server Express + EF”;应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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