adding connection string during installation of vb.net

落爺英雄遲暮 提交于 2019-12-25 07:24:55

问题


this is a follow up for my last question which is on: adding connection string during installation of vb.net project

this is the code that I have so far but the "Configuration" in the line:

Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)

has a blue line and I can't run the program because of it. I converted the C# code to that one and the blue line appears. what I'm trying to do here is to get the a string that I can use for the connection string which will be used by the app.config.

Imports System.ComponentModel

Imports System.Configuration.Install

Public Class 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

End Class


回答1:


I don't know if this is it but some things I have noticed from the code you have posted:

  • ConfigurationManager comes from the System.Configuration namespace, as does the Configuration class but you don't seem to have Imports System.Configuration in your code (only Imports System.Configuration.Install)...I would try adding a Imports System.Configuration statement if you don't have this already

  • Have you added a reference to the System.Configuration assembly in your installer project? (Sorry, I don't remember if it comes with this assembly reference added by default)



来源:https://stackoverflow.com/questions/15684897/adding-connection-string-during-installation-of-vb-net

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