views:

100

answers:

2

We decided to use the registry for handling our deployment with connection strings in our VB.net application.

The requirements are:

  1. If the program cannot connect to the server, first check the registry for a connection string. IF not, create the folder and fill in the name, type, and data.
  2. Make sure its encrypted.

I have never edited or created anything in the registry. Where do I start? If anybody has any code samples or links to articles I would really appreciate it.

+8  A: 

It looks like this tutorial would be a good source for the problem. I would strongly recommend against storing the connection string in the registry. It adds more work and more dependencies on the current operating environment. Additionally, configuration files are more portable and are better suited for storing property related information. If you use a settings file the supporting admins and your support people will thank you. [Compared to placing the information in the registry.

monksy
Unfortunately I have to do what the bosses say, but I totally agree with you.
broke
+1 for not using the registry for this. Use app.config instead.
Joel Coehoorn
App.config or another configuration file.
monksy
+6  A: 

Totally agree with Steven here, but if you have to do it...here is some info From MSDN (link to all you need to know at the bottom). The following example reads, increments, and then writes a DWORD value to HKCU:

Imports Microsoft.Win32
Dim regVersion As RegistryKey
regVersion = 
Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\TestApp\\1.0", True)
If regVersion Is Nothing Then
    ' Key doesn't exist; create it.
    regVersion = 
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\TestApp\\1.0")
End If

Dim intVersion As Integer = 0
If (Not regVersion Is Nothing) Then
    intVersion = regVersion.GetValue("Version", 0)
    intVersion = intVersion + 1
    regVersion.SetValue("Version", intVersion)
    regVersion.Close()
End If

http://msdn.microsoft.com/en-us/library/aa289494%28VS.71%29.aspx

Sean
Sweet Ill defiantly use this
broke
... but don't forget that RegistryKey implements IDisposable, so that you should wrap each instantiation in a "using" statement. Something that is neglected in far too many MSDN samples...
Joe