Moe DeShong
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?
ASKER
It's a windows app. Code? Need more info.
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.
ASKER
Ok, but how do you do via code?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I would assume it would have to be placed in the formload event?
ASKER
Answered my own question.
AppointmentsTableAdapter.C onnection = Nothing
AppointmentTableAdapter.co nnection = "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.
AppointmentsTableAdapter.C
AppointmentTableAdapter.co
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.
ASKER
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):
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.
if (production)
{
connection = prod_conn;
}
else if (qa)
{
connection = qa_conn;
}
else if (dev)
{
connection = dev_conn;
}
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.co nnection.C onnectionS tring = "new connection string"
AppointmentTableAdapter.co
if web that should be in the web.config file
otherwise search in app.config