tags:

views:

38

answers:

2

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  A: 

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

James
A: 

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

Shawn Mclean