• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 85
  • Last Modified:

Storing a Connection String in My.Settings?

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
BlakeMcKenna
Asked:
BlakeMcKenna
  • 3
  • 2
1 Solution
 
Andrea AntonangeliCommented:
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
 
BlakeMcKennaAuthor Commented:
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
 
Andrea AntonangeliCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
BlakeMcKennaAuthor Commented:
Actually, you can do it. I've seen the code before but don't have it nor do I remember it...
0
 
käµfm³d 👽Commented:
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
 
BlakeMcKennaAuthor Commented:
Thanks KaufMed...that worked great!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now