1

I have my projects setup as follows (repository pattern):

  1. myProj.Data (Contains the xDB.mdf) [Library]
  2. myProj.Service (Uses myProj.Data) [Library]
  3. myProj.WebApp (Uses myProj.Service) [ASP.NET Website]

In 1. I access my Database via Linq to Sql. The app.config looks like this:

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

When I try to retrieve some data via the web, I get this error thrown from the Service Project:

An attempt to attach an auto-named database for file D:\MyProject\XDb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

From this code:

return (from p in repository.GetPostMedia() where p.PostId == postId select p).ToList();

2 Answers 2

2

Check in Management Studio that you don't have that database already attached, if so detach it and try again.

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

Comments

0

I moved the database from the myProj.Data into myProj.Web App_Data folder and it worked.

Comments

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.