How to deploy or publish Windows app with SQL Server database


I have developed a C# application with a SQL Server database. When I try to publish the application to test it >> it works correctly on my machine (that include the database in SQL Server data folder) >> but when I move that published app to another machine it doesn't work.

I want to know the simplest way to deploy the project with its database together

I am using this connection string in my app.config:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="cs" providerName="System.Data.ProviderName" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\KBank.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" /> </connectionStrings> </configuration>

What should I do in order to place the database with the deployed app and dynamically modify the connection string for the database in app.config?

the exception shown when i open the project on the users machines says:


An Attempet to Attach an auto-named database for file C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\KBank.mdf Failed, a database with the same name exists or specified file cannot be opened, or its location on UNC share


it seems it is unable to read the SQL DataBase


Your application can not find the database file that is specified in the connection string talk less of connection to it. This is because the database is <strong>auto-named</strong> rather than a data file. All you need to do is to make the database an attached <strong>data file</strong> to the package so that when deployed the database will go along with it. To do this, on visual studio IDE, on the publish tab chose "Application Files" change the Publish status of the database file from "Include Auto" to "Data File", then validate. This will add the database file to ur application upon publish and deployment. To access project property, 1)With Visual studio 2010/2012 - Click Project Menu -> Properties -->

I hope this helps u. If not i'll try to explain again. Stay Blessed


I have resolved my problem > the problem was that i didn't add a Local Database to my project solution.. so when i try the project on another machine the application couldn't find the specified connection sting that have the path:


C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\KBank.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True


but when i added the local db to my project solution the connection string path became :




it has been attached with the project files successfully thank you


  • How Do I Select Multiple Nodes At A Time From Treeview Control Using C# And Visual Studio 2013
  • MDF table content is deleted when starting application from within VS
  • Sections must only appear once per config file. See the help topic for exceptions.Why?
  • how do add multi sql dependency to this code?
  • ASP.Net MVC 3 Configuration
  • SQL Server Operating system error 5: “5(Access is denied.)”
  • localhost cannot find stored procedure 'dbo.aspnet_CheckSchemaVersion'
  • Unable to update the table where pimary key is located
  • How to select parent ids
  • My select command doesn't work
  • Python - Pyodbc Connection error
  • How to setup a reverse proxy on several ports (tcp & udp)
  • LightSwitch Beta 1 looking for SQL Express instead of full SQL instance
  • Passing Query Parameters from HTML/JS App to Azure Server Script
  • What is the best data type to store boolean values in a database
  • Kinect API written solely in Java without native functions?
  • How can I determine if process is 32 or 64Bit from a handle?
  • How to create a custom Powershell operator?
  • Compress a file with GZipStream while maintaining its meta-data
  • powershell Get-Counter -ComputerName parameter on Windows 7
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • Private IP address in reserved subnet range
  • How To Customize ASP.NET Chart Databound To SqlDataSource
  • how do i write assembly code from c#?
  • Memory error in python- how to use more memory
  • Differences in dis-assembled C code of GCC and Borland?
  • x64 applications using gdi+: what are the consequences on performance?
  • Algorithm for a smudge tool?
  • Nant, Vault & Windows Integrated Authentication
  • Counter field in MS Access, how to generate?
  • Javascript + PHP Encryption with pidCrypt
  • Websockets service method fails during R startup
  • SVN: Merging two branches together
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • Benchmarking RAM performance - UWP and C#
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]