0

I would like to add database in App_Data folder in my application.

This is my connection string in Web.config file

<connectionStrings>
    <add name="DefaultConnection" 
         providerName="System.Data.SqlClient" 
         connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-TestTask-20151223145656;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\TestTaskDb.mdf" />
</connectionStrings>

And this is my TestTaskDb class

public class TestTaskDb : DbContext
{
    public TestTaskDb() : base("name=DefaultConnection")
    {
    }

    public DbSet<Vacancy> Vacancies { get; set; }
}

As I can see there is TestTaskDb.mdf in my App_Data folder

enter image description here

But I'm not sure, if I send my project to other person, and he open it on his computer, build and run application, would it work with my database and its data or not?

1
  • A .mdf file is a SQL Server database file - to do anything with it, that other person must also have some SQL Server instance (Express or higher - NOT SQL Server Compact / CE!) installed to make use of that database file Commented Dec 24, 2015 at 12:26

1 Answer 1

1

But I'm not sure, if I send my project to other person, and he open it on his computer, build and run application, would it work with my database and its data or not?

That will depend on whether you send him the contents of the App_Data folder. So basically if you want him to use your database then make sure you have sent the proper mdf and ldf files to him.

Sign up to request clarification or add additional context in comments.

3 Comments

So if I send him my project with all folders and files which it contains, it will work on his computer and shows all data from database when he run it on his computer from VS?
Yeap, that's the point of an embedded database. You don't need a centralized server for it. Of course you should never use anything like that in a production because this can't scale.
Oh, thanks. Actually it's my test task to get a job but I'm studing and I have a little expierence, so I'm not sure about these things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.