Storing Connection Strings in Registry?

2019-08-02 01:52发布

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.

2条回答
爷的心禁止访问
2楼-- · 2019-08-02 02:33

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.

查看更多
Animai°情兽
3楼-- · 2019-08-02 02:40

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

查看更多
登录 后发表回答