Results 1 to 4 of 4

Thread: Securing Connection String Data

  1. #1
    hop6919 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Sep 2009
    Posts
    2
    Reputation
    0

    Securing Connection String Data

    Hi All,

    I wonder if you can help me understand a piece of code a little more. I'm currently working my way through an MCTS Self Paced Training Kit (70-505, Chapter 5, Lesson 6). This particular lesson teaches you about securing connection string data. It explains the basic premise, and asks you to 'copy and paste' the following code into Visual Studios to demonstrate it. I do like to understand why a particular piece of code works before I move on, but for the life of me I can't quite see it.

    Here is the code: (a reference is also needed to System.Configuration in the properties)

    Code:
    
    Imports System
    Imports System.Configuration
    
    Public Class Form1
    
    Private Sub EncryptConnectionString()
    
    ' Get the configuration file
    Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    
    ' Create the provider name
    Dim provider As String = "DataProtectionConfigurationProvider"
    
    ' Encrypt the ConnectionStrings
    Dim connStrings As ConfigurationSection = config.ConnectionStrings
    connStrings.SectionInformation.ProtectSection(provider)
    connStrings.SectionInformation.ForceSave = True
    config.Save(ConfigurationSaveMode.Full)
    End Sub

    I understand that this code:
    a] creates the configuration file
    b] puts the connection string in the config file
    c] encrypts the section with connection string in it

    What I'd like to know is how the code actually infers this! I can see that:
    connStrings.SectionInformation.ProtectSection(prov ider) encrypts the section named DataProtectionConfigurationProvider.

    But I can't understand how the code that 'gets the configuration file' works, and how the application would know how to search that file for it, as opposed to within the compiled data - there seems to be no method called that instructs the application to do that!

    As they say.... ask a stupid question and you'll feel a fool for five minutes....

    Thanks very much in advance!

  2. #2
    Robert_Zenz's Avatar
    Robert_Zenz is offline VB.NET Forum Idol
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2008
    Location
    Vienna, Austria
    Posts
    503
    Reputation
    339
    As far as I see it, it loads the Projects-Configuration file. You can have a look at that file under My Project -> Settings, it's a generated XML-File which will be deployed with your application (if needed), and were you can store variables which have to survive a restart of the application (pretty similar to an ini file). With OpenExeConfiguration the app is looking for that configuration file in the same directory as the exe, if the file is missing, it should create a new one or (which is most likely) throw an exception.

    Bobby
    Don't give TypeCasting Errors a chance, turn ON Option Strict!

  3. #3
    hop6919 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Sep 2009
    Posts
    2
    Reputation
    0
    Thanks - that's a little clearer. After some more research, I realised that the code I didn't understand was the method!

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,363
    Reputation
    1544
    I'm not sure whether it will help you further or not but you may like to have a [ame="http://www.vbforums.com/showthread.php?t=532768"]look at this[/ame].

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking