[英]An attempt to attach an auto-named database for file <FILE> failed. A database with the same name exists
I have the ASPNETDB.MDF database in the App_Data folder of my project. 我的项目的App_Data文件夹中有ASPNETDB.MDF数据库。
I'm getting an error when I try to add a user: 尝试添加用户时出现错误:
MembershipUser user = Membership.CreateUser(viewModel.Username, viewModel.Password, viewModel.Contact.Email,
viewModel.SecurityQuestion, viewModel.SecurityAnswer, true, out createStatus);
The error is: 错误是:
An attempt to attach an auto-named database for file C:\\Users\\Steven\\documents\\visual studio 2010\\Projects\\MyApp\\MyApp.WebUI\\App_Data\\ASPNETDB.MDF failed. 尝试为文件C:\\ Users \\ Steven \\ documents \\ visual studio 2010 \\ Projects \\ MyApp \\ MyApp.WebUI \\ App_Data \\ ASPNETDB.MDF附加自动命名的数据库失败。 A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
存在具有相同名称的数据库,或者无法打开指定的文件,或者该数据库位于UNC共享上。
My web.config has this connection string and membership info: 我的web.config具有以下连接字符串和成员资格信息:
<connectionStrings>
<add name="ASPNETDB" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ASPNETDB" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ASPNETDB" applicationName="/" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ASPNETDB" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
I have a feeling my connection string is wrong, but I really have no idea. 我有一种感觉,我的连接字符串是错误的,但是我真的不知道。
While directory permissions, create new user "network service" and configure permissions 获得目录权限后,创建新用户“网络服务”并配置权限
Replace |Data directory| 替换|数据目录| to "C:\\inetpub\\wwroot..."
到“ C:\\ inetpub \\ wwroot ...”
It is successful. 成功了。
以管理员身份运行VisualStudio可解决开发过程中的此问题。
For starters will you please give this connection string a try? 对于初学者,您可以尝试一下此连接字符串吗?
<connectionStrings>
<add name="ASPNETDB" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
I am also curious to know are you able to access the database at all from your application. 我也很好奇,您是否可以从您的应用程序访问数据库。 From your error, I would assume no.
根据您的错误,我认为不会。
将IIS管理器中站点的应用程序池更新为ASP.NET v4.0,为我解决了此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.