7

I have several Entity Framework Code First DbContext objects that use a custom Initializer.

In the initializer, the call to

context.Database.Create();

creates the database in SQL Server.

The Data and Log files are created in directories per the Database Settings in SQL Server.

I would like different DbContext subclasses to have different Data and Log file paths. Can I specify the paths somehow when creating the database, or must I detach/move/attach in a separate step after the database has been created?

1 Answer 1

4

You can always use the AttachDBFilename keyword in the connection string. See the documentation of SqlConnection.ConectionString for more information.

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

2 Comments

Any idea how I can specify the LOG file to be in a separate folder?
It is not possible from the connection string. The log file will be the same as the filename you specify with "_log.ldf" appended.

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.