【问题标题】:adding connection string during installation of vb.net在安装 vb.net 期间添加连接字符串
【发布时间】:2013-03-19 01:43:03
【问题描述】:

这是我最后一个问题的跟进:adding connection string during installation of vb.net project

这是我到目前为止的代码,但行中的“配置”:

Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)

有一条蓝线,因此我无法运行该程序。我将 C# 代码转换为该代码并出现蓝线。我在这里要做的是获取一个字符串,该字符串可用于 app.config 将使用的连接字符串。

导入 System.ComponentModel

导入 System.Configuration.Install

公共类InstallerClass

Public Sub New()
    MyBase.New()


    InitializeComponent()

End Sub


<RunInstaller(True)> _
Partial Public Class MyInstaller
    Inherits Installer


    Partial Public Class MyInstaller
        Inherits Installer


        Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)


            MyBase.Install(stateSaver)

            Dim targetDirectory As String = Context.Parameters("targetdir")

            Dim param1 As String = Context.Parameters("Param1")

            Dim param2 As String = Context.Parameters("Param2")

            Dim param3 As String = Context.Parameters("Param3")


            Dim exePath As String = String.Format("{0}MyWindowsFormsApplication.exe", targetDirectory)

            Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)

            config.AppSettings.Settings("Param1").Value = param1

            config.AppSettings.Settings("Param2").Value = param2

            config.AppSettings.Settings("Param3").Value = param3

            config.Save()

        End Sub

    End Class




End Class

结束类

【问题讨论】:

  • 我建议你用新内容编辑你原来的问题。

标签: vb.net visual-studio-2010 connection connection-string app-config


【解决方案1】:

我不知道是不是这样,但我从您发布的代码中注意到了一些事情:

  • ConfigurationManager 来自 System.Configuration 命名空间,Configuration 类也是如此,但您的代码中似乎没有 Imports System.Configuration(只有 Imports System.Configuration.Install)...我会尝试如果您还没有,请添加 Imports System.Configuration 声明

  • 您是否已将reference 添加到安装程序项目中的System.Configuration 程序集? (抱歉,我不记得是不是默认添加了这个程序集引用)

【讨论】:

  • 感谢@nkvu,我在参考中添加了 System.Configuration 程序集,蓝线消失了。我会试着弄清楚其他事情现在是如何工作的。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
  • 2020-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-04
相关资源
最近更新 更多