CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

View Poll Results: What method do you store connection strings

Voters
3. You may not vote on this poll
  • as a class file

    1 33.33%
  • in the app.config file

    2 66.67%
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    [RESOLVED] Best Practice/Opinions on Connection String

    Just wondering what the general opinion is for storing connections strings in a windows application? As a separate class or in the app.config file?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Best Practice/Opinions on Connection String

    Master DB access isn't necessary, so user ID in config file is usually good enough. User logs in after that
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Best Practice/Opinions on Connection String

    What do you mean by "as a separate class"?

  4. #4
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: Best Practice/Opinions on Connection String

    As a completely different class file

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Best Practice/Opinions on Connection String

    Let's clear up something - class has nothing to do with file. You can have multiple classes in one file. You can also use the 'partial' class keyword and have one class span many files. When talking about classes, what file the class resides in is irrelevant (because after compiling the source files are no longer in use).

    Are you talking about hardcoding the connection string into a member of the class? If so, this should be avoided.

  6. #6
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: Best Practice/Opinions on Connection String

    Thank you for your input

  7. #7
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: [RESOLVED] Best Practice/Opinions on Connection String

    One last question.

    How would I use the app.config file if the location of the DB is dependant on where the application launches.

    Example: The application is a portable app designed to be run on a thumb drive.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: [RESOLVED] Best Practice/Opinions on Connection String

    Quote Originally Posted by forgottenhart View Post
    How would I use the app.config file if the location of the DB is dependant on where the application launches.
    You are better of using some other criteria to determine an app configuration rather than the install location of the app.

    For example, if you app launches from the thumb drive, then write a LaunchMode setting in the app.config and set it to ThumbDrive.

    There are many ways to accomplish the same thing - basing an app's action on where it's installed from is rarely a good thing.

  9. #9
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: [RESOLVED] Best Practice/Opinions on Connection String

    Thank you. Is there perhaps a few articles that you can direct me to for some reading/studying.

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

Featured