Solved

Changing Connection String dynamically

Posted on 2009-03-31
5
157 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
Comment Utility
Hi,
 You can save that configuration into settings.
http://www.emoreau.com/Entries/Articles/2007/03/AppSettings-revisited.aspx
0
 

Author Comment

by:LeeLiam
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect.

Thanks for your help.

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

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

12 Experts available now in Live!

Get 1:1 Help Now