We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

VB 2005 How to change My.Settings Connection String

Medium Priority
386 Views
Last Modified: 2013-11-25
I have searched and found several threads on changing the connection string values in VB 2005, but have yet to find an easy way to do it.  Also, as an alternative I tried writing the connection string into an XML file, but the string would never let me connect.  Has anyone had any luck with storing a connection string in a manner that it can be easily changed in the event the datasource changes?
Comment
Watch Question

A simple solution might be to write your own string and in each statement your use String.Format method to check for the proper string to place into your connection string. i.e.

Dim con As String = String.Format(" your path to your server... '{0}'... ", txtdatabaseSource)
Make a form or place to change this path and use a textbox to enter this location, this would enter the text you typed into the textbox and place into the connection string, you will need to follow this format '{0}' the single quotes are needed to make this work.

I have used similar ideas for queries.

Hope this helps...

Disclaimer, not an expert yet...

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Accually the single quotes are needed in queries, they should not be needed in your connection string.

Author

Commented:
I'm sorry, but what does the '{0}' refer to?
- Whatever string is in your textbox, or any other place you can draw the string from.
If textbox1.text is "something" then when you write:
 Dim con As String = String.Format(" your path to your server... '{0}'... ", txtdatabaseSource)' it will be
                                                       " your path to your server... something ..."
It just adds the string inside of your connection string. I know this may seem weird(and it might be) but this will work as long as the info is right. After all it is just a string, and this is a simple manipulation of that string.
{0} is the first value, {1} is the second value, etc... and you can reuse the {X} as many times as you need.
" The {0} day is always the {1}!", txt1.text, txt2.text) = "The first day is always the hardest" where
txt1.text = "first" and txt2.text = "hardest"
These could also be comboBox1.selected.item.tostring just as well!

Happy coding...
For clarity sake line 3(above) should have looked like
Dim con As String = String.Format(" your path to your server... {0}... ", textbox1.text)' it will be...

Also I have not tested this for your purposes, hope this is something you can do easily enough, and to reiderate you will not need the single quotes around the braces {}, unless you use this method in a sql statement.

Dim sql as string = Format("SELECT * FROM myTable WHERE column1 = '{0}' OR '{1}' ", txt1.text, txt2.text)

Makes an interface for custom searching.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.