I have developed a small application with SQL SERVER back end and I also make an installer for the application with Indigo Rose Setup factory 8.0. What I need is I want to automatically create the database back end with specific user account during the installation of the application.
我用SQL SERVER后端开发了一个小应用程序,我还使用Indigo Rose Setup factory 8.0为该应用程序安装了一个安装程序。我需要的是我想在安装应用程序期间使用特定的用户帐户自动创建数据库后端。
Before the installer a user is asked to install either SQL server or SQL express as prerequisite, when the database is installed the installation of the software continues. I tried to do using SQL script but I don’t how to do it before installation on the installer software. I though also to embed the database creation program in the main application and it will execute on the user need upon the completion of the installation but I have never tried it before whether it works or not.
在安装程序之前,要求用户安装SQL Server或SQL Express作为先决条件,在安装数据库时,将继续安装软件。我尝试使用SQL脚本,但在安装程序软件上安装之前我不知道如何操作。我还要将数据库创建程序嵌入到主应用程序中,它将在安装完成后根据用户需要执行,但我从未尝试过它是否有效。
Incase if it need I developed the system using C# with SQL SERVER 2005 backend. So would you please give me some answer to tackle the problem? Thank you
如果需要,我可以使用带有SQL SERVER 2005后端的C#开发系统。那么请你给我一些解决问题的答案?谢谢
2 个解决方案
#1
3
The simplest way would be to have the installer call sqlcmd.exe to run a sql script. To call that, you will need to know the data source (location) of the sql instance. You will need to get that from the user. For example, machinename, machinename\instancename or typically sqlexpress is machinename\SQLExpress.
最简单的方法是让安装程序调用sqlcmd.exe来运行sql脚本。要调用它,您需要知道sql实例的数据源(位置)。您需要从用户那里获得。例如,machinename,machinename \ instancename或通常sqlexpress是machinename \ SQLExpress。
http://msdn.microsoft.com/en-us/library/ms165702.aspx
You can also side step the pre-req and install sqlexpress for your customer. There's a cmdline to install it:
您也可以支持pre-req并为您的客户安装sqlexpress。有一个cmdline来安装它:
http://msdn.microsoft.com/en-us/library/ms144259.aspx
Another option with no sql dependencies is to write your own custom action (command line/API), parse between the GO statements in the script and execute with ADO.net.
没有sql依赖项的另一个选项是编写自己的自定义操作(命令行/ API),在脚本中的GO语句之间进行解析并使用ADO.net执行。
Another option outside of setup is to separate setup and configuration. Setup only lays down bits and the database is created at runtime via a configuration phase of the runtime of the product. This has many benefits including being able to update your bits (either with a patch or automatically) after the setup phase and before the configuration phase. You can also give a better interactive experience and handle issues at runtime - with setup, your choices are to fail setup and roll it back which is a bad experience.
设置之外的另一个选项是分离设置和配置。安装程序仅放下位,并且数据库是在运行时通过产品运行时的配置阶段创建的。这有许多好处,包括能够在设置阶段之后和配置阶段之前更新您的位(使用补丁或自动)。您还可以提供更好的交互式体验并在运行时处理问题 - 通过设置,您的选择是设置失败并将其回滚,这是一种糟糕的体验。
Hope that helps.
希望有所帮助。
#2
2
Bryan already gave you good advice. My recommendation would be to have the application itself be capable of deploying the database by running the deployment script(s). You can use a library like dbutilscmd that parses the .sql
scripts and executes the batches from inside the application. I would also advise to have your scripts be capable of upgrading the database, not just deploy it. This will be very handy when you release v. 2.0 of the application. See Version Control and your Database.
布莱恩已经给了你很好的建议。我的建议是让应用程序本身能够通过运行部署脚本来部署数据库。您可以使用像dbutilscmd这样的库来解析.sql脚本并从应用程序内部执行批处理。我还建议您的脚本能够升级数据库,而不仅仅是部署它。当你发布v.2.0的应用程序时,这将非常方便。请参阅版本控制和您的数据库。
One thing to consider is that often the initial database deployment requires an elevated privilege context. There are some options, see Teach Your Apps To Play Nicely With Windows Vista User Account Control.
需要考虑的一件事是,初始数据库部署通常需要提升的权限上下文。有一些选项,请参阅使用Windows Vista用户帐户控制教您的应用程序。
#1
3
The simplest way would be to have the installer call sqlcmd.exe to run a sql script. To call that, you will need to know the data source (location) of the sql instance. You will need to get that from the user. For example, machinename, machinename\instancename or typically sqlexpress is machinename\SQLExpress.
最简单的方法是让安装程序调用sqlcmd.exe来运行sql脚本。要调用它,您需要知道sql实例的数据源(位置)。您需要从用户那里获得。例如,machinename,machinename \ instancename或通常sqlexpress是machinename \ SQLExpress。
http://msdn.microsoft.com/en-us/library/ms165702.aspx
You can also side step the pre-req and install sqlexpress for your customer. There's a cmdline to install it:
您也可以支持pre-req并为您的客户安装sqlexpress。有一个cmdline来安装它:
http://msdn.microsoft.com/en-us/library/ms144259.aspx
Another option with no sql dependencies is to write your own custom action (command line/API), parse between the GO statements in the script and execute with ADO.net.
没有sql依赖项的另一个选项是编写自己的自定义操作(命令行/ API),在脚本中的GO语句之间进行解析并使用ADO.net执行。
Another option outside of setup is to separate setup and configuration. Setup only lays down bits and the database is created at runtime via a configuration phase of the runtime of the product. This has many benefits including being able to update your bits (either with a patch or automatically) after the setup phase and before the configuration phase. You can also give a better interactive experience and handle issues at runtime - with setup, your choices are to fail setup and roll it back which is a bad experience.
设置之外的另一个选项是分离设置和配置。安装程序仅放下位,并且数据库是在运行时通过产品运行时的配置阶段创建的。这有许多好处,包括能够在设置阶段之后和配置阶段之前更新您的位(使用补丁或自动)。您还可以提供更好的交互式体验并在运行时处理问题 - 通过设置,您的选择是设置失败并将其回滚,这是一种糟糕的体验。
Hope that helps.
希望有所帮助。
#2
2
Bryan already gave you good advice. My recommendation would be to have the application itself be capable of deploying the database by running the deployment script(s). You can use a library like dbutilscmd that parses the .sql
scripts and executes the batches from inside the application. I would also advise to have your scripts be capable of upgrading the database, not just deploy it. This will be very handy when you release v. 2.0 of the application. See Version Control and your Database.
布莱恩已经给了你很好的建议。我的建议是让应用程序本身能够通过运行部署脚本来部署数据库。您可以使用像dbutilscmd这样的库来解析.sql脚本并从应用程序内部执行批处理。我还建议您的脚本能够升级数据库,而不仅仅是部署它。当你发布v.2.0的应用程序时,这将非常方便。请参阅版本控制和您的数据库。
One thing to consider is that often the initial database deployment requires an elevated privilege context. There are some options, see Teach Your Apps To Play Nicely With Windows Vista User Account Control.
需要考虑的一件事是,初始数据库部署通常需要提升的权限上下文。有一些选项,请参阅使用Windows Vista用户帐户控制教您的应用程序。