Solved

Storing a Connection String in My.Settings?

Posted on 2014-09-16
6
77 Views
Last Modified: 2014-09-17
I have not used the My.Settings feature very much so I'm not clear on all it's rules.

I have a setting called "strDBConnection" established in My.Settings. It's defined as "Connection String" along with it's value.

In design mode, I have a statement that won't work (see attachment). How do I resolve this?

Thanks!
Screenshot.jpg
0
Comment
Question by:BlakeMcKenna
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Andrea Antonangeli
Comment Utility
You must define the setting as "User" to avoid the readonly attribute of the property you define in My.Settings

You probably have defined it as "Application"
0
 

Author Comment

by:BlakeMcKenna
Comment Utility
Yes, I do but I need the scope of that variable to be "Application". Is there a way to dynamically set that setting "strDBConnection" to where it will persist until changed again?
0
 
LVL 1

Expert Comment

by:Andrea Antonangeli
Comment Utility
I'm afraid there is no way to change the value of "strDBConnection" if you define it as "Appication".
It is Readonly by design.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:BlakeMcKenna
Comment Utility
Actually, you can do it. I've seen the code before but don't have it nor do I remember it...
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Connection strings should really go in the <connectionStrings> section of your app.config--it's a commonly accepted convention. You can access the values by way of:

Dim conString As String = System.Configuration.ConfigurationManager.ConnectionStrings("con string name").ConnectionString

Open in new window


...once you've added a reference to System.Configuration.dll.
0
 

Author Closing Comment

by:BlakeMcKenna
Comment Utility
Thanks KaufMed...that worked great!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now