Persistent settings

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi



I need to store the path to db in my app. I have used app setting for this.
Unfortunately various clients have different db paths and I have set them up
once on each client location. The problem is that when I send them updates
and they uninstall the old version and reinstall the new version the setting
is reset to my settings. This is because the old configuration file is
deleted and replaced by the new one included in the app. Is there a way to
have a setting that is not overwritten by an application reinstall?



Thanks



Regards
 
Hi

I need to store the path to db in my app. I have used app setting for this.
Unfortunately various clients have different db paths and I have set them up
once on each client location. The problem is that when I send them updates
and they uninstall the old version and reinstall the new version the setting
is reset to my settings. This is because the old configuration file is
deleted and replaced by the new one included in the app. Is there a way to
have a setting that is not overwritten by an application reinstall?

Thanks

Regards

I have always used a separate file for things like this - perhaps you
could use an Xml file that is stored in the application's base
directory. If you are worried about the sensitive nature of connection
strings, you could even have your app encrypt/decrypt that file.

Thanks,

Seth Rowe
 
Many thanks for that. Would be grateful for a link on how to handle xml
files.

Thanks

Regards
 
John said:
I need to store the path to db in my app. I have used app setting for
this. Unfortunately various clients have different db paths and I have set
them up once on each client location. The problem is that when I send them
updates and they uninstall the old version and reinstall the new version
the setting is reset to my settings. This is because the old configuration
file is deleted and replaced by the new one included in the app. Is there
a way to have a setting that is not overwritten by an application
reinstall?

Take a look at 'My.Settings' and the "Settings" tab in "My Project" if you
are using VS 2005.
 
Many thanks for that. Would be grateful for a link on how to handle xml
files.

Thanks

Regards

Here's a quick console application that briefly demonstrates how to
use an Xml file:

Imports System.Xml

Module Module1

Sub Main()
Console.WriteLine("Saving Settings...")
SaveSettings()
System.Threading.Thread.Sleep(500)
Console.WriteLine(GetSetting("ConnectionString"))
Console.Read()
Dim fileName As String = String.Format("C:\Document and
Settings\{0}\Desktop\MyXmlFile.Xml", Environment.UserName)
If System.IO.File.Exists(fileName) Then
System.IO.File.Delete(fileName)
End If
End Sub

Public Sub SaveSettings()
Dim writer As XmlWriter = XmlWriter.Create(String.Format("C:
\Documents and Settings\{0}\Desktop\MyXmlFile.Xml",
Environment.UserName))
writer.WriteStartElement("Settings")
writer.WriteStartElement("ConnectionString")
writer.WriteString("YourConnString")
writer.WriteEndElement() ' ConnectionString
writer.WriteEndElement() ' Settings
writer.Close()
End Sub

Public Function GetSetting(ByVal nodeName As String) As String
Dim doc As New XmlDocument
doc.Load(String.Format("C:\Documents and Settings\{0}\Desktop
\MyXmlFile.Xml", Environment.UserName))
Dim node As XmlNode = doc.GetElementsByTagName(nodeName)(0)
Return node.InnerText
End Function

End Module

Thanks,

Seth Rowe
 
Back
Top