如何在安装时指定sql server的connectionstring [英] how to specify connectionstring of sql server while installation

查看:367
本文介绍了如何在安装时指定sql server的connectionstring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端安装c#windows应用程序。在应用程序中,我需要一个连接字符串。如何在安装时进行配置。另外,我想打包sql express设置和.Net框架设置与我的应用程序设置。是否可以这样做?

I am installing c# windows application in client place. In the application, I need a connection string. How can it be configured while installation. Also I want to pack the sql express setup and .Net Framework setup with my application setup. Is this posssible?

推荐答案

如果使用Visual Studio安装程序,可以向安装程序添加自定义页面,一个自定义操作,用于处理该自定义页面的结果。例如,在VS2010 Professional中:

If you're using the Visual Studio Installer, you can add a custom page to the installer and add a custom action that handles the result of that custom page. For example, in VS2010 Professional:


  1. 创建Visual Studio安装程序设置项目

  2. 添加项目输出到安装程序,添加快捷方式,否则根据您的喜好配置安装程序。 (即假设不会为您配置连接字符串,并按照您想要的方式配置其他配置。现在提交到您选择的源代码控制,以便重试如果您有问题

  3. 在解决方案资源管理器中右键单击安装项目,然后选择视图>用户界面

  4. 开始(在作为步骤3的结果出现的用户界面窗口中)并选择添加对话框

  5. 选择文本框(A) )或文本框(C),然后单击确定(据我所知,选择A / B / C中的哪一个无关紧要)。

  6. 用户界面窗口中的文本框(A),并将其向上上方确认安装拖动,因为您可能希望连接字符串对话框在

  7. 右键点击文本框(A),然后选择属性窗口。

  8. 自定义属性(它们将显示在解决方案资源管理器下方/旁边的属性选项卡中:
  1. Create a Visual Studio Installer setup project
  2. Add the project output to the installer, add shortcuts and otherwise configure the installer to your liking. (i.e. Assume for now that it won't configure the connection string for you and get everything else configured the way you want it. Now commit to your source control of choice so you can try again if you have problems)
  3. Right click on the setup project in Solution Explorer and choose View > User Interface
  4. Right click on "Start" (in the "User Interface" window that appeared as a result of step 3) and choose "Add Dialog"
  5. Choose one of "Textboxes (A)", "Textboxes (B)" or "Textboxes (C)" and click OK (as far as I'm aware it doesn't matter which of A/B/C you choose).
  6. Click on "Textboxes (A)" in the "User Interface" window and drag it up above "Confirm Installation", as you probably want the connection string dialog to appear before the "we're ready to install, are you sure" window.
  7. Right-click on "Textboxes (A)" and choose "Properties Window"
  8. Customise the properties (they'll appear in the "Properties" tab that sits underneath / next to Solution Explorer to:

  1. 将Edit2Visible,Edit3Visible和Edit4Visible设置为false

  2. Edit1标记为连接字符串(或您选择的文字)

  3. Edit1属性为SQL_CONNECTION_STRING(或您选择的名称 - 自定义操作将引用)


  • 创建并运行安装程序以确保安装仍然正确。

  • 接下来你需要做的是编写一个自定义动作,将连接字符串存储到app.config文件中。 在安装程序项目中将安装App.Config设置为自定义操作的问题覆盖了它,因此我将留给您阅读,使用它。

    The next thing you'll need to do is write a custom action to store the connection string to the app.config file. The question Setup App.Config As Custom Action in Setup Project covers it so I'll leave it to you to read that and make use of it.

    据我所知,没有办法在Visual Studio安装程序中嵌入依赖项,但我建议把它作为另一个问题因为您的问题中确实有两个问题=)

    As far as I'm aware there's no way to embed dependencies inside a Visual Studio Installer, but I'd suggest hiving it off as another question as you really have two questions in your question =)

    这篇关于如何在安装时指定sql server的connectionstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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