我正在使用 Web 套接字和 SqlDependency 来构建游戏服务器。 SqlDataReader 的错误表明我应该调用 SqlDependency.Start。我在 Global.Asax 中包含以下内容:
SqlDependency.Start(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
该行始终以 SqlException 结尾,并显示消息:
Cannot attach the file 'C:...aspnet-ProjectName-11111111111.mdf' as database 'aspen-ProjectName-11111111111'.
我两天来一直在努力解决这个问题。我已经启动了一个新的 MVC 4 WebAPI 应用程序,具有基本模型、上下文和种子,但无法解决此错误。我尝试了以下各种解决方案:
https://social.msdn.microsoft.com/Forums/en-US/ae041d05-71ef-4ffb-9420-45cbe5c07fc5/ef5-cannot-attach-the-file-0-as-database-1?forum=adodotnetentityframework https://social.msdn.microsoft.com/Forums/en-US/ae041d05-71ef-4ffb-9420-45cbe5c07fc5/ef5-cannot-attach-the-file-0-as-database-1?forum=adodotnetentityframework
ASP.NET MVC4 Code First - “无法将文件附加为数据库”异常 https://stackoverflow.com/questions/15701935/asp-net-mvc4-code-first-cannot-attach-the-file-as-database-exception
EF5: 无法将文件“{0}”附加为数据库“{1}” https://stackoverflow.com/questions/13275054/ef5-cannot-attach-the-file-0-as-database-1
不用找了。我在 Visual Studio 2012 中运行 MVC4 API,SQL Server 是 2014。
这是数据库连接问题,对吗?我的AppData文件夹中的.mdf文件(它和日志文件都存在于两个项目中)无法连接到SQL Server?还有,帮忙?