Database error ASP.NET
I have my projects setup as follows (repository pattern):
- myProj.Data (Contains the xDB.mdf) [Library]
- myProj.Service (Uses myProj.Data) [Library]
- myProj.WebApp (Uses myProj.Service) [ASP.NET Website] 开发者_如何学JAVA
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();
Check in Management Studio that you don't have that database already attached, if so detach it and try again.
I moved the database from the myProj.Data into myProj.Web App_Data folder and it worked.
精彩评论