如何将我的SQL Server 2008 R2数据库添加到我的Visual Studio 2010安装文件中? [英] How to add my SQL Server 2008 R2 database to my Visual Studio 2010 Setup File?

查看:293
本文介绍了如何将我的SQL Server 2008 R2数据库添加到我的Visual Studio 2010安装文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的客户位置安装Windows应用程序.它是一个多用户应用程序. 10个系统和1个服务器.因此,我将在所有10个系统上安装客户端设置,并在服务器系统上安装服务设置.

I want install my Windows application at my client location. It is a multiuser application. 10 systems with 1 server. So I install client setup on all the 10 systems and service setup on the server system.

如何保护客户端服务器中的数据库?我正在使用VS2010和SQL Server 2008 R2.在不安装SQL Server Management Studio Express的情况下,如何安装数据库?以及如何在服务设置中添加我的数据库?有人可以给我看看这种应用程序的例子吗?

How to secure my database in client server? I am using VS2010 and SQL Server 2008 R2. With out installing SQL Server Management Studio Express, how to install my database? And how to add my database in service setup? Can anybody show me an example for this type of application?

推荐答案

Windows安装程序没有任何现成的支持来与应用程序一起部署数据库,您将不得不编写自己的组件,该组件将在安装过程中创建数据库部署,然后将其插入MSI.我在项目中也做过同样的事情.遵循步骤.

windows installer does not have any out of the box support to deploy database with along with the application, You will have to write your own component which creates the database during the deployment and plug it in with the MSI. I have done the same in my project. follow the steps.

Creating database with Console App

  1. 首先忘记Windows Installer.
  2. 创建控制台应用程序.
  3. 使用SMO(SQL server Management Object)或简单的Sql Command执行脚本的添加方法.
  4. 此处查看我的答案 .sql文件,然后在SQL Server上执行.
  5. 您要做的是保留一个.sql脚本文件,该文件可以在执行时创建数据库.
  6. 您必须将该文件路径传递给控制台应用程序中具有的方法.
  1. First forget about the Windows Installer.
  2. Create a console application.
  3. Add method which uses either SMO(SQL server Management Object) or simple Sql Command to execute script.
  4. Check my answer here which could read a .sql file and execute it on SQL server.
  5. What you have to do is keep a .sql script file which could create the database when executed.
  6. You have to pass that file path to the method that you have in the console app.

Executing console app during the installation

  1. 现在,您有了一个控制台应用程序,该应用程序可以在执行时创建数据库,只要将正确的脚本文件路径传递给该方法即可.
  2. 将此控制台exe和sql脚本文件添加到您的MSI软件包中.因此,这两个都将放置在应用程序安装文件夹下.
  3. 安装程序类添加到您的项目.
  4. 在install方法中只需执行控制台exe文件.
  1. Now you have a console app which could create a database when executed, Provided that right scrip file path is passed to the method.
  2. Add this console exe and the sql script file to your MSI package. So both of these will be placed under the application installation folder.
  3. Add a installer class to your project.
  4. within the install method simply execute the console exe file.

Code

public override void Install(IDictionary stateSaver)
{
   base.Install(stateSaver);

   Process process = new Process();
   ProcessStartInfo info = new ProcessStartInfo();
   process.StartInfo = info;

   info.FileName = Path.Combine(this.Context.Parameters["targetdir"], "ConsoleApp.exe");
   info.UseShellExecute = false;

   process.Start();

}

这篇关于如何将我的SQL Server 2008 R2数据库添加到我的Visual Studio 2010安装文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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