1

I am trying to configure a different location for my local db.

I read an article on configuring connection strings and it suggests I can replace |DataDirectory| in the web config with ~/MyDirectory where ~ is the web app root. So I have input the connection string as:

<connectionStrings>
<add name="Context" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Context-20130829161219;Integrated Security=SSPI;AttachDBFilename=~/MyDirectory/Context-20130829161219.mdf"
  providerName="System.Data.SqlClient" />

Unfortunately, when I run the app it doesn't seem to create the db at all. I can imagine it's only something very small that I am doing wrong but I would appreciate if someone can point me in the right direction.

Many Thanks

2 Answers 2

2

Lets try with below string it will help you

<add name="Context" connectionString="metadata=res://*/Models.Datacontext.csdl|res://*/Models.Datacontext.ssdl|res://*/Models.Datacontext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDb)\SQLInstance;initial catalog=Context-20130829161219;persist security info=True;user id=sa;password=Yourpassword;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

or replace your Source=(LocalDb)\SQLInstance;initial with Source=.\SQLInstance;initial

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

Comments

1

Try running the Update-Database cmdlet from the package manager console - you should at least see some output indicating why it doesn't work.

2 Comments

Thanks for the suggestion. I get the following error: A file activation error occurred. The physical file name '~/MyDirectory/Context-20130829161220.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.
Yes, when replacing ~/MyDirectory/ with |DataDirectory| everything works fine

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.