Link to home
Start Free TrialLog in
Avatar of Moe DeShong
Moe DeShongFlag for United States of America

asked on

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?
Avatar of adilet_nasirdinov
adilet_nasirdinov
Flag of Italy image

what is your application? windows or web?
if web that should be in the web.config file
otherwise search in app.config
Avatar of Moe DeShong

ASKER

It's a windows app.  Code?  Need more info.
Avatar of kaufmed
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.
Ok, but how do you do via code?
I've never worked with the config file so don't know how to look it up and make the necessary changes.
Try accessing it using My.Settings.settingname but to be able to change it, you need to change its scope to User.
ASKER CERTIFIED SOLUTION
Avatar of Moe DeShong
Moe DeShong
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would assume it would have to be placed in the formload event?
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.
Figured it out a posted my solution.
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.
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?"
Or

AppointmentTableAdapter.connection.ConnectionString = "new connection string"