我将连接字符串连接到我的Entity Framework MVC4程序时遇到了一些麻烦。
这是我的连接字符串:
<connectionStrings>
<add name="testContext"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:\folders\SQL\SQL\App_Data\TEST1.mdf;"
providerName="System.Data.SqlClient" />
</connectionStrings>
这是我的错误代码:
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Directory lookup for the file "C:\folders\SQL\SQL\App_Data\TEST1.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
答案 0 :(得分:0)
用户似乎正在运行应用程序,因为无法访问c:\ folders ....目录。
另一个问题(一旦解决了第一个问题)就是你错过了连接字符串中的“Database”参数。
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:\folders\SQL\SQL\App_Data\TEST1.mdf;Database=dbnamehere;"