Results 1 to 5 of 5

Thread: [2008] Store comnnection string in My.Settings

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    [2008] Store comnnection string in My.Settings

    Can someone please show me how to store the connection string to my Access mdb in my project's My.Settings ?

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Store comnnection string in My.Settings

    Open the Settings tab of the project properties and add a Setting of type ConnectionString. Follow the Protected Configuration link in my signature to see how to edit it at run time and encrypt it for security.

    Note that if you add a Data Source to your project for the database then it will save the connection string to the config file by default.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Store comnnection string in My.Settings

    Quote Originally Posted by jmcilhinney
    Note that if you add a Data Source to your project for the database then it will save the connection string to the config file by default.
    That is great info. Thanks very much.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    515

    Re: [2008] Store comnnection string in My.Settings

    Quote Originally Posted by jmcilhinney
    Follow the Protected Configuration link in my signature to see how to edit it at run time and encrypt it for security.
    Do I need to import anything from your Protected Configuration project or do I follow the code in your FormEncrypt's Tools menu ?

    Code:
            'Open the primary config file.
            Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    
            'Encrypt the connections strings section.
            With config.ConnectionStrings.SectionInformation
                .ProtectSection(Nothing)
                .ForceSave = True
            End With
    
            'Save the changes.
            config.Save(ConfigurationSaveMode.Full)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Store comnnection string in My.Settings

    Have you read the documentation for all the types and members I'm using in that code? That's how you will gain understanding. If you're just copying and pasting someone else's code without understanding it then you're not learning.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width