470,833 Members | 1,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

System.Configuration Save Does Not Save

SR
I am trying to use the Configuration object provided with the .NET 2.0
framework. I see that when I call the Save function it does update the
<application>.exe.config file. However, when I close the application and
check the <application>.exe.config file again, it has reverted back to how
it was when the application was started.

Is there something I am doing or not doing? Here is part of my code: (And
before anyone writes it, I know I can use the DatabaseConfiguration object,
but this is simply for learning this object at this point.)

Thanks!

My Config Class:

Public Class FileGenClass : Inherits ConfigurationSection

<ConfigurationProperty("DatabaseServer")> _
Public Property DatabaseServer() As String
Get
Return Me.Item("DatabaseServer")
End Get
Set(ByVal value As String)
Me.Item("DatabaseServer") = value
End Set
End Property

<ConfigurationProperty("DatabaseName")> _
Public Property DatabaseName() As String
Get
Return Me.Item("DatabaseName")
End Get
Set(ByVal value As String)
Me.Item("DatabaseName") = value
End Set
End Property

<ConfigurationProperty("DatabaseUser")> _
Public Property DatabaseUser() As String
Get
Return Me.Item("DatabaseUser")
End Get
Set(ByVal value As String)
Me.Item("DatabaseUser") = value
End Set
End Property

<ConfigurationProperty("DatabasePassword")> _
Public Property DatabasePassword() As String
Get
Return Me.Item("DatabasePassword")
End Get
Set(ByVal value As String)
Me.Item("DatabasePassword") = value
End Set
End Property
....

Saving Code:

Try
moFileGen =
CType(ConfigurationManager.GetSection("DatabaseSet tings"), FileGenClass)

If moFileGen Is Nothing Then
moFileGen = New FileGenClass
Dim oSettings As New Settings
oSettings.btnCancel.Enabled = False
If oSettings.ShowDialog(Me) = Windows.Forms.DialogResult.OK
Then
moFileGen.DatabaseServer = oSettings.txtDBServer.Text
moFileGen.DatabaseName = oSettings.txtDBName.Text
moFileGen.DatabaseUser = oSettings.txtUser.Text
moFileGen.DatabasePassword = oSettings.txtPassword.Text

Dim oConfig As Configuration =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None)
oConfig.Sections.Add("DatabaseSettings", moFileGen)
oConfig.Save()
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
....
Apr 28 '06 #1
0 1497

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Supra | last post: by
reply views Thread by Andrzej Kaczmarczyk | last post: by
8 posts views Thread by Alberto | last post: by
1 post views Thread by Shannon Richards | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.