How to genenerate Database backend during Software installation?

删除回忆录丶 提交于 2020-01-02 07:52:25

问题


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.

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.

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


回答1:


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.

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:

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.

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:


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.

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.



来源:https://stackoverflow.com/questions/8322341/how-to-genenerate-database-backend-during-software-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!