Solved

Changing Connection String dynamically

Posted on 2009-03-31
5
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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