How to deploy application with sql server database on clients
Solution 1:
Option 1 - Setup Project
Using Visual Studio you can create a setup project and install prerequisites that you need during installation.
The installation process is very simple and the end user can install application and prerequisites after clicking next buttons.
Here are the steps for Creating a Setup Project:
1- Create a c# Windows Forms Application
- Create a C# Windows Forms Project
- Add New Item and Add SQL Server Database to your application
- Add a table to your application and fill some data in it
- Show the data in your main form.
2- Create a Setup Project
- Add new project → setup and deployment → setup project
- Right Click on Setup project and Add project Output and select primary output from your main project
- Right Click on Setup project and Add project Output and select content files from your main project
- Right CLick on setup project and Click Properties and click Prerequisites and select SQL Server Express
- Select .Net Framework
- Select Windows Installer
- Select radio button Download prerequisites from the same location as my application.
- Right Click on Users Desktop at left pane and add new Shortcut and select application folder, primary output from SampleApplication, and click ok and the rename the short cut to what you need.
- Rebuild solution.
- Rebuild Setup Project
- Go to Output directory of setup project and run setup.exe
It's that easy.
For more information take a look at following docs articles:
- How to: Create or Add a Setup Project
- How to: Install Prerequisites in Windows Installer Deployment
- Walkthrough: Using a Custom Action to Create a Database at Installation
Option 2 - ClickOnce
Using Visual Studio another option is using ClickOnce publishing.
To do so, in properties of your project, in publish tab, click prerequisites button, you can select SQL Express in prerequisites. This way, you only need to set your database files to copy in output directory, and use AttachDbFileName in connection string: Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\Database.mdf; Initial Catalog=Master"
.
For more information take a look at the following docs article:
- How to: Publish a ClickOnce Application using the Publish Wizard
Solution 2:
LocalDB
is Microsoft's current recommended solution. It allows you to connect to a database file directly, without having to install an instance of the Full SQL Server, or SqlExpress. It is fully compatible with the full version of SQL server. There are no installation requirements on the client end, as the libraries are packages along with your application when it is built.
You can read more about it here.
Solution 3:
you can instal sql express With silent installation in your setup this way not showing any wizard for install sql express Read this Link