Changing binding source connection

Once a binding source is created the connection string is placed as an application setting in the project settings. That's fine while I'm developing. Once I install on a different computer the database location changes and the binding source no longer has the right connection information.  How do I let the binding source know where the new data location is?
LVL 2
Moe DeShongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

adilet_nasirdinovCommented:
what is your application? windows or web?
if web that should be in the web.config file
otherwise search in app.config
0
Moe DeShongAuthor Commented:
It's a windows app.  Code?  Need more info.
0
käµfm³d 👽Commented:
That's the beauty of configuration files:  all you should have to do is change the part of the config file that changes between systems. In your case, you would change the "Data Source" property to point to the new server. Your database name (Initial Catalog) should be the same.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Moe DeShongAuthor Commented:
Ok, but how do you do via code?
0
Moe DeShongAuthor Commented:
I've never worked with the config file so don't know how to look it up and make the necessary changes.
0
CodeCruiserCommented:
Try accessing it using My.Settings.settingname but to be able to change it, you need to change its scope to User.
0
Moe DeShongAuthor Commented:
Can't change it to user.  It is locked.  

I just notice the tableadapter has a connection property.  Would something like this work?:

AppointmentsTableAdapter.Connection = Nothing
AppointmentTableAdapter.connection = "My connection"?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moe DeShongAuthor Commented:
I would assume it would have to be placed in the formload event?
0
Moe DeShongAuthor Commented:
Answered my own question.  

AppointmentsTableAdapter.Connection = Nothing
AppointmentTableAdapter.connection = "My connection"?

Works perfect.  Thanks for the input.  I'm a newbie with the table adapters.  Always wrote my own sql.  
TableAdapters do make short work of coding.
0
Moe DeShongAuthor Commented:
Figured it out a posted my solution.
0
käµfm³d 👽Commented:
But why would you want to change it via code? Changing the connection via code means you end up having to do something like this (pseudo-code):

if (production)
{
    connection = prod_conn;
}
else if (qa)
{
    connection = qa_conn;
}
else if (dev)
{
    connection = dev_conn;
}

Open in new window


What happens if the prod server goes out of commission, and you have to load the program onto a new server? Now you have to locate this place in code, and you have to change the prod code to point to the new server. Then you have to recompile the app, then redistribute/install it. If you put the connection info in your configuration file, then you only have to open a text file, make the change, save the file, then run the program.
0
käµfm³d 👽Commented:
and you have to load the program onto a new server?
That should have said, "and you have to load the DB onto a new server?"
0
CodeCruiserCommented:
Or

AppointmentTableAdapter.connection.ConnectionString = "new connection string"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.