Tags:
vb.net
Hej Alle..
Jeg har lavet et lille program til og forbinde til en SQL-Server. Jeg vil så lave en muglighed for at ændre opsætningen (APP.config)..
Her er hvad jeg har nu, jeg kan i få den til og finde Attributten i App.config. Den viser MSGBOX CON-1 men aldrig CON-2..
Hvad kan være galt ??
App.Config :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Mamut_Kalk.My.MySettings.Mamut_Dantank_SqlServer"
connectionString="Data Source=SERVER\MAMUT;Initial Catalog=Client00020004;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.diagnostics>
<sources>
--------------------------------------------
Class :
Imports System.Configuration
Imports System.Xml
Public Class AppConfigFileSettings
Public Shared Sub UpdateAppSettings(ByVal KeyName As String, ByVal KeyValue As String)
Dim XmlDoc As New XmlDocument()
XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
For Each xElement As XmlElement In XmlDoc.DocumentElement
If xElement.Name = "connectionStrings" Then
MsgBox("CON-1 FUNDET")
For Each xNode As XmlNode In xElement.ChildNodes
If xNode.Attributes(0).Value = KeyName Then
MsgBox("CON-2 FUNDET")
xNode.Attributes(1).Value = KeyValue
End If
Next
End If
Next
XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
End Sub
End Class
-----------------------------------
Knap (Gem):
Private Sub Save_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save_Button.Click
Dim Server_string As String
Server_string = "Data Source=" & ServerADD_TextBox.Text & ";Initial Catalog=" & Database_TextBox.Text & ";Integrated Security=True"
AppConfigFileSettings.UpdateAppSettings("connectionString", Server_string)
MsgBox("Application Settings has been Changed successfully.")
End Sub
-----------------------------------