Click here to Skip to main content
15,888,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have small asp.net mvc project with database on SQL server. I need to present it at the job interview so I need to send it via email. What I need to know what is the best way, how to export and connect the mdf file to the project so the database is always tied to the project folder. Can you give me any tips please?

What I have tried:

I was thinking about just copy mdf file to project and change the connection string
Posted
Updated 7-Jan-18 16:29pm
Comments
F-ES Sitecore 7-Jan-18 12:49pm    
Send them a backup of the database and let them restore as they see fit.

1 solution

Hi Jakub,

I recommend best practice for database file as the following

1. Export the Script - you can export the SQL server database script with data as the script file. Then, you can create a new database and run it the script file whereas you want it.

(or)

2. Project folder inside - you can keep the SQL server database file (.MDF) on the App_Data folder inside the project folder. then you can attach the database file (.MDF) using SQL Server Management Studio whereas you want it. you can use the database connection string in your project.


Please let me know if you want any help
 
Share this answer
 
Comments
Jakub Provaznik 8-Jan-18 18:12pm    
I have a question for second point. If I keep mdf file in the App_Data, do I need to set up for localdb?
san2debug 8-Jan-18 22:06pm    
if you have kept the MDF file in App_Data folder. you can use the AttachDbFilename property in the connection string as the following

<add name="SQLConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />

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