Changing Application-Wide Connection String at Runtime

Compeek

Member
Joined
Feb 23, 2009
Messages
5
Programming Experience
5-10
Hello,

Let me just first say that I learned VB about 7 years ago, but I moved on to web development about 5 years ago. Since then, I have dabbled with VB.NET enough to get used to the differences between VB 6 and VB.NET, but I didn't really start actively using it again until a couple of weeks ago. I am a very capable programmer, but my VB skills are a little rusty, and VB.NET is still somewhat new to me.

I'm writing a simple piece of software to manage donations and donors for a mission in town. The database I'm using is an Access 2007 file. To keep it simple, I just let VB automatically create my TableAdapters, BindingSources, etc when I created a new Database Connection with the wizard.

My problem is that I need to be able to easily change the connection string of the TableAdapters at runtime, but VB set up the connection string as a setting with a scope of Application for the project, making the setting read-only at runtime. The only option I can think of is to manually set the connection strings of all my TableAdapters every time the program runs, but that seems like too much of a hassle. I have multiple forms with one or two TableAdapters on each, and I don't want to have to keep track of all of them. I could write a subroutine to handle changing all of them, but again, that seems like I would be making it more complicated than necessary.

I have tried to Google solutions to the problem, but I just can't find a good answer. So my question is, what is the best approach to what I am trying to do? I would really like to only have one connection string to change that affects all my TableAdapters, but I'll do what is necessary.

Thanks much in advance for the help. :D
 
Thanks for replying

Bear in mind that Ken posted a good few years ago.. What is it that youre struggling with, poly?

It would have been nice to see the code mentioned but I have this working myself by just changing from my.settings.connstring to mysettings.item("connstring") which works well.

Thanks for taking time to check in though, appreciated.
 
Back
Top