Update SQL database

Hi,

As part of updating the application (winform app), I need to update the database schema. Problem is that the database connection info is available only via the app.config file on each clients machine. I cannot hardcode the connection info in the sqlcmd batch file as it could be different for all clients because I allow them to create the application database on any machine on their network.

Any ideas on how I can accomplish this task?

Well, if the connection details are in the app.config file, then that's the file you have to read. So, read the file, get the values you need, then connect to the database and make any changes.

I realize that - but that means that I have to write the updating of the database logic inside my application. I was hoping not to do that and leave all updates to wyupdate - that is why wyupdate is there in the first place - to take care of application updates. So, there is no way that wyupdate could look at the app.config file for connection params and then execute a batch file with those values?

So, there is no way that wyupdate could look at the app.config file for connection params and then execute a batch file with those values?

No, configuration files can be in infinite different formats, and the data inside can be in infinite number of forms. It's impossible for us to write an algorithm of such a scope. That's why we allow you to execute files before/after updates. This allows you to do things that are specific to your app (in your case updating a database with the configuration setting stored in an XML file located at a specific location).

What you should do is make a tiny VB.NET or C# app to read the XML data, then pass that back to the batch file. Or just have the small executable make the appropriate calls to the SQL DB you want to update.

Thanks, Wyatt. I knew what the answer was going to be:). I have written the database update logic in a little exe that sits in the same folder as the main application. Through wyupdate, I will invoke that exe and that will update the database for me using the connection info in the main application app.config file. That way, my main application is not littered with database update stuff and I can re-use this exe for n number of db updates.