Solved

Changing Connection String dynamically

Posted on 2009-03-31
5
160 Views
Last Modified: 2012-05-06
I am converting a VB6 app to .NET. In VB6, the connection string was set in code. The user could open a different database using an Open Dialog box. After selecting the file, the new path and name was saved for that and all future connections.

I don't know how to handle this change in .NET. I'm setting up data sources for most forms. When I create the data source, the Data Source Configuration Wizard asks for a connection string. Apparently, this gets saved in some configuration file. This would be fine if the database name and path were identical for every user, but I don't want to be forced into this scenario.

How can I give the user a dialog box to select a file and then, each time they launch the program, it will use that for the connection? I seemed to have read the connection string is read only.

Thanks.
0
Comment
Question by:LeeLiam
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24032686
Hi,
 You can save that configuration into settings.
http://www.emoreau.com/Entries/Articles/2007/03/AppSettings-revisited.aspx 
0
 

Author Comment

by:LeeLiam
ID: 24033300
Thank you. That is an excellent article and it will take me some time to fully digest it.

In the meantime, can I place a line of code like:

Me.TableAdapter.Connection.ConnectionString = OleConn.ConnectionString

before using the table adapter? Will this override the stored connection string?

Thanks.
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24033345
Yes it will.
You save your new connection string in the settings and then you assing that to your datatable (on form load event for example)
0
 

Author Comment

by:LeeLiam
ID: 24033545
Perfect.

Thanks for your help.

(I assume you meant 'passing'. :) )
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24033567
LOL, it was a typo :)
Glad I could help!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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