0

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

intense
  • 21
  • 1
  • if your client all machines are in LAN then u can do one thing,just chenge in master machine/where sql installed change in it..automatically chages have been done at all client pcs – Vidhi Apr 30 '15 at 08:16
  • related to users next question: http://stackoverflow.com/questions/29965381/connect-to-database-from-sqlcmd, arguably a duplicate. – Tanner Apr 30 '15 at 10:47

1 Answers1

0

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.

Community
  • 1
  • 1
hbulens
  • 1,872
  • 3
  • 24
  • 45
  • How would I be able to choose the instance if the clients only have localDB installed, and it is a local data-file bundled in the project though? – intense Apr 30 '15 at 08:27
  • First, that doesn't sound like very good design to me. But if there is a SQL server hosted on the machine, then you should ensure you just the right computer name (could be an IP address too) and instance. Examples could be: sqlcmd -S "(localdb)\.\MySharedInstance" sqlcmd -S ".\MySharedInstance" sqlcmd -S "(localdb)\MySharedInstance" sqlcmd -S "GREENHORNET\MySharedInstance" sqlcmd -S ".\LOCALDB#SH04FF8A" sqlcmd -S "GREENHORNET\LOCALDB#SH04FF8A" – hbulens Apr 30 '15 at 08:32
  • The clients do not have an instance setup, the connection string is like so: connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True" providerName="System.Data.SqlClient" So since it uses a data file, I cannot connect to it via sqlcmd with a shared instance. How can I connect with the data file? – intense Apr 30 '15 at 10:26