[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Changing Connection String dynamically

Posted on 2009-03-31
5
Medium Priority
?
166 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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