Click here to Skip to main content
15,892,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just finished building a C# Windows Form (WinForm) application using Entity Framework 6 database first model, and after publishing it using Microsoft Visual Studio Installer projects, I have realized that the database has not been added to the application.

How can I attach the database along with the .EXE file? I have selected the needed prerequisites (.NET Framework and SQL Server Express).

I am using Entity Framework 6 (EF6) and my database has a username and password (SQL Server authentication).

I have already included the .mdf file in the project and in the output directory.

check the attached images below:
attached DB and connection string
exception thrown

What I have tried:

I have tried the solutions here and here

I have also tried to use SQL(localDB) instead of SQL Server Express, but it throws the same exception.
Posted
Updated 30-Nov-19 4:29am

1 solution

Well, if EF6 is configured approrpiately, it should create your schema on the app's first usage. An Alternative is to "generate scripts" in your database inside SSMS, and simply run those scripts to create the schema inside the database, and even populate static data in the appropriate tables.

I wrote a 6-part article series that describes a method for running agents in SQL Express, which provides an example of generating the schema from SQL scripts from within an application.

SQLXAgent - Jobs for SQL Express - Part 1 of 6[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900