Updating once deployed

2019-08-20 04:47发布

问题:

I have searched everywhere, however have not found a straightforward answer.

I have deployed a WinForms C# .NET application, which uses a LocalDb SQL Server 2012 Express database. The database is thus a data file contained in the project. I would like to add some columns to a number of tables, and since the project is deployed at a lot of clients, I would like to send them a script, or a file of some sort, and once they run it, their database would have these changes.

How can this be done? There is no SQL Management Studio, so the users cannot login and run a script in there. I need it to be run based on the LocalDb, and cannot find any solutions online

回答1:

I would consider a batch file that executes sql scripts, like so:

sqlcmd -S <ComputerName>\<InstanceName> -i C:\Temp\ClearTables.sql

This article provides a fairly good answer.