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.
这是我第一次部署使用SQL Server Express数据库的应用程序。我正在使用Entity Framework Model First来联系数据库。然后我创建了一个安装向导,其中包含Install Shield以安装应用程序。
These are Steps that I'v done to Install The Application in Destination Computer :
这些是我在目标计算机中安装应用程序所做的步骤:
- Installing MS SQL Server Express (DEST)
- 安装MS SQL Server Express(DEST)
- Installing The Program using Setup file (DEST)
- 使用安装文件(DEST)安装程序
- Detach Database from SQL server and Copy Related .mdf ,.ldf file to the Destination Computer.
- 从SQL Server分离数据库和将相关的.mdf,.ldf文件复制到目标计算机。
- Attach database file in destination computer using SQL Server Management Studio.
- 使用SQL Server Management Studio在目标计算机中附加数据库文件。
I know server names and SQL name Instances are different and my program can't run correctly with the Old Connection String.
我知道服务器名称和SQL名称实例不同,我的程序无法使用旧连接字符串正确运行。
I'm Beginner at this, and I want to know what should I do in the Destination Computer to make the program run?
我是初学者,我想知道我应该在目标计算机上做什么来使程序运行?
- should I find a way to change the connection string on runtime?!
- 我应该找到一种在运行时更改连接字符串的方法吗?!
- or is there any way to modify installshield project and it do this work for me? (installshield is professional edition)
- 或者有没有办法修改installshield项目,它为我做这个工作? (installshield是专业版)
- could you suggest me what to do?
- 你能建议我做什么吗?
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.
在我的搜索中,我看到WiX可以做到这一点,但我发现它很复杂,而且我没有足够的时间来学习它。我需要尽快部署应用程序。
Thanks alot.
非常感谢。
1 个解决方案
#1
4
Few hints for using LocalDB in your project:
在项目中使用LocalDB的几点提示:
-
Download SQL Express LocalDB 2014 here. You can install it silently with single command like this
在此处下载SQL Express LocalDB 2014。您可以使用这样的单个命令以静默方式安装它
msiexec /i SqlLocalDB.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
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.在您的VS项目中包含您的.MDF,并将属性设置为Copy in new,以便在构建期间将其复制到bin文件夹,以便它自动包含在安装程序中。
-
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.cs中)检查,数据库文件是否存在于所需位置(例如%PUBLIC%\ YourApp \ Data)(所有本地用户本地使用MDF的WPF桌面应用程序)。如果没有,请将.mdf文件从app install 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" />
修改app.config,使您的连接字符串如下所示:
Connection timeout should be increased, since LocalDB exe is launched when you first try to connect to it.
应该增加连接超时,因为第一次尝试连接时会启动LocalDB exe。
You can also use Database.CreateIfNotExists, but I have never tried it.
您也可以使用Database.CreateIfNotExists,但我从未尝试过。
#1
4
Few hints for using LocalDB in your project:
在项目中使用LocalDB的几点提示:
-
Download SQL Express LocalDB 2014 here. You can install it silently with single command like this
在此处下载SQL Express LocalDB 2014。您可以使用这样的单个命令以静默方式安装它
msiexec /i SqlLocalDB.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
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.在您的VS项目中包含您的.MDF,并将属性设置为Copy in new,以便在构建期间将其复制到bin文件夹,以便它自动包含在安装程序中。
-
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.cs中)检查,数据库文件是否存在于所需位置(例如%PUBLIC%\ YourApp \ Data)(所有本地用户本地使用MDF的WPF桌面应用程序)。如果没有,请将.mdf文件从app install 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" />
修改app.config,使您的连接字符串如下所示:
Connection timeout should be increased, since LocalDB exe is launched when you first try to connect to it.
应该增加连接超时,因为第一次尝试连接时会启动LocalDB exe。
You can also use Database.CreateIfNotExists, but I have never tried it.
您也可以使用Database.CreateIfNotExists,但我从未尝试过。