0

My C# project connects to SQL Server to save and retrieve data. What's the process to deploy such a project so that I could install the application on another PC? And how do I include the database tables that already contain previously made entries?

My windows application uses a SQL Server database to save user information and retrieve. Should I include a SQL Server installation along with the built project in order to run in on another PC?

Thank you!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jay
  • 4,873
  • 7
  • 72
  • 137
  • erthlink, e4rthdog here, listen up :)..Write some more details about your application. do you use entity Framework? or just plain ado.net or something else to access the data? SQL Server is gonna be the same or hosted on the other PC? Provide some more info to help you – e4rthdog Oct 26 '14 at 06:10
  • If you want to run this on another PC, then SQL Server has to be either installed locally on that machine (e.g. the free SQL Server **Express**), or there has to be a SQL Server instance on the network that you can reach from that machine (e.g. a server in that machine's LAN somewhere) where you can install your database onto. – marc_s Oct 26 '14 at 07:54

2 Answers2

1

The easy stuff first.

1) If you are using Entity Framework you can enable migrations (if u havent done it already) and then when you point your connection string to another server Entity seed method will take care of everything.

Read about EF migrations HERE.

2) If you are not using EF then you have to backup and restore the database to the new server. you can use SQL Server Management Studio to export your DB (or only database schema without data) and then import it to the other server.

UPDATE After the comments addition:

No you cant just "include" the SQL Server installation in your app. SQL Server is a huge monster that comes in its own installation.

IF you are looking for a lightweight database that you could install in a pc, you can use:

-Access

-SQLIte

-SQL Server Express (a crippled SQL Server)

-SQL Server Compact You can install it directly via nuget ( Microsoft.SqlServer.Compact package)

SQL server editions comparison

Personally i love the following combination on simple apps:

SQLite + Dapper (micro ORM, somethign like a very light Entity Framework)

e4rthdog
  • 5,103
  • 4
  • 40
  • 89
  • Ah okay :) I'm not using Entity Framework. Should I include a SQL Server installation along with the built project in order to run in on another PC? I'm also compiling an InstallShield Wizard, is it possible to include the SQL server installation with it? – Jay Oct 26 '14 at 06:19
  • @Earthling is it do difficult to change your data access implementation? how it is now? – e4rthdog Oct 26 '14 at 07:46
  • Thank you very much sir, let me try this and get back to you :) – Jay Oct 26 '14 at 10:04
0

Assuming you are at the point you want to deploy your code, here are possible steps you can follow:

  1. build your app in 'Release mode' to get a faster/lighter version: Debug Visual Studio Release in .NET. enter image description here
  2. Take the executables, resource files (if not embedded) etc. and package them for delivery (by default, those files are located in the Bin\Release folder). You can simply ZIP the files or you can create an installer (like MSI)
  3. Application and the database are deployed separately. If you have data in you DB, you can back it up and restore it on the other machine. Backup: How do I back up a database to a .bak file? Restore: How can I restore a database backup file (.bak) from SQL Server 2012 into SQL Server 2008 Express? If the data is just staging data, you can you the seed method is you are using EF. If you are not using EF, you can export your DB schema to .sql file that can be run on the target machine manually or automatically by the installer.
Community
  • 1
  • 1
Rotem Varon
  • 1,597
  • 1
  • 15
  • 32