publish a project with local database
Did you include the database as "Application File"? If not do the following (at least this is how I am doing it):
Project -> Properties -> Publish -> Application Files
Here set the values for your .mdf and the xx_log.ldf as follows:
Now still in the Publish tab go on Prerequisites. Here you have to check the following depending on what database you are using.
This will download SQL Server Express for the client who is installing your application.
You will also have to change the connection string to a generic path. I suppose the database lies somewhere inside your project folder /bin I guess, not sure anymore. So adjust your connection string to something like:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True
I therfor recommend using a resource file or app.config
But basically i think your problem is that the pc you are installing on does not have SQL Server installed. So just follow the steps above in Prerequisites. The other steps will enable you to deploy the database to the project folder without moving it to a certain folder manually.
I hope this helps.
Local Database after publishing C#
string constring = $"Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + Directory.GetCurrentDirectory().ToString() + "\\BarcodeDB.mdf;Integrated Security=True";
This fixed it for me
Problem publishing ASP.NET application with a SQL Server database
When you're testing with Visual Studio, you should connect to the local copy of your database. When you're ready to publish your application, copy the database to the remote sql server and attach it. The copy of your application which is published should then connect to the uploaded database on that server.
That way you have one environment for testing and one for real use. There shouldn't be any need for Visual Studio to connect to the remote database.
P.S. To allow you to connect to different databases in different environments, usually you set your database connection string in the web.config file. So if you create different config transforms for each build configuration (e.g. debug and release) then visual studio will create the correct version of the config file when you do a Publish operation. See https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations for info about configuration transforms.
Related Topics
Reverse Sorted Dictionary in .Net
Combobox.Selectedtext Doesn't Give Me the Selectedtext
Why Aren't Generic Type Constraints Inheritable/Hierarchically Enforced
Efficient Way to Round Double Precision Numbers to a Lower Precision Given in Number of Bits
How to Scroll to Element in Uwp
Does Foreach Automatically Call Dispose
What Does "Displayclass" Name Mean When Calling Lambda
C# Windows 'Open with >' Context Menu Behaviour
Concurrentdictionary Getoradd Async
Draw Multiple Freehand Polyline or Curve Drawing - Adding Undo Feature
How to Have a Variable Number of Generic Parameters
Escape Quote in C# for JavaScript Consumption
Linq: from a List of Type T, Retrieve Only Objects of a Certain Subclass S
How to Find the Position of a Cursor in a Text Box? C#
Take Screenshot of Multiple Desktops of All Visible Applications and Forms