I have a batch file that contains commands to restore a database using patches from a folder. I want to make a GUI application which can execute SQL commands but rather than applying all of the patches in the folder.
I currently have the following sqlcmd in the batch file:
sqlcmd -E -S(local) -i "c:\temp\MergedPatchFiles.sql"
The patches in the folder are numbered – I need a way to find the current patch number of the database and the number of patches in the folder and use a for each loop to apply only the patches that are required.
How can I execute an ‘apply patch’ SQL command using C# on a specified database?
You can do it in several ways:
Process.Startto executesqlcmddirectly (or even the batch file directly…)