开发者

What's the best way to process database upgrades in Windows and Web App?

开发者 https://www.devze.com 2023-01-29 12:29 出处:网络
I know how to create scripts, but it\'s knowing how I implement these scripts within a windows app or web application?

I know how to create scripts, but it's knowing how I implement these scripts within a windows app or web application?

Focusing on a web app, I have all upgrade scripts in a folder like: \install\upgrade_1.4.99.sql, upgrade_1.4.101.sql etc

C# code checks current code database version with c# version and loops through each sql script in order and runs the script.

If the user is not an administrator, display appropriate message stating an upgrade is imminent... something similar (logs out user). Administrators (us) are redirected to upgrade webpage and runs the scripts displaying failure or success for each script. A Failure rolls back the SQL Transaction.

We basically have several instances of one web application and frustrated with the manual upgrades we use to manage.

The most prominent issue we had was data upgrades... always missing essential data transfers like static data (configuration settings etc). So we use RedGate for schema and data upgrade scripting.

So is my method above of upgrading websites the best way to go about this? Can I assume the same process for windows applications?

Also I'm certain my method of reading the script file could be improved. We simply read each line of 开发者_JAVA百科text in the sql file and wait for a "GO" and save this string into an array before processing them all. (I didn't write this code). The process involves one big Begin and Commit Trans... just not sure if this right or not.

Sorry not sure if there are too many questions here.


You can actually run an entire batch script at once against SQL Server:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/43e8bc3a-1132-453b-b950-09427e970f31

As far as what the best way to run updates in any sort of automated fashion? I don't think there is any one great way of doing it. It's whatever works best for your system. This goes without saying, but be sure to test scripts in a separate environment as much as possible.

HTH, Brian

0

精彩评论

暂无评论...
验证码 换一张
取 消