开发者

Database error ASP.NET

开发者 https://www.devze.com 2022-12-18 21:30 出处:网络
I have my projects setup as follows (repository pattern): myProj.Data (Contains the xDB.mdf) [Library]

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]
  4. 开发者_如何学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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号