尝试附加文件℃的自动命名的数据库;文件>失败。具有相同名称的数据库存在 [英] An attempt to attach an auto-named database for file <FILE> failed. A database with the same name exists

查看:155
本文介绍了尝试附加文件℃的自动命名的数据库;文件>失败。具有相同名称的数据库存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目的App_Data文件夹的ASPNETDB.MDF数据库。

I have the ASPNETDB.MDF database in the App_Data folder of my project.

我得到一个错误,当我尝试添加用户:

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);

该错误是:

附加的文件C自动命名的数据库的尝试:\\用户\\史蒂芬\\文档\\ Visual Studio 2010的\\项目\\ MyApp的\\ MyApp.WebUI \\ App_Data文件\\ ASPNETDB.MDF失败。具有相同名称的数据库不存在,或者指定的文件无法打开,或它位于UNC共享。

我的web.config中有此连接字符串和会员信息:

My web.config has this connection string and membership info:

<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.

推荐答案

运行VisualStudio的以管理员​​身份在开发过程中解决了这个问题。

Running VisualStudio as Administrator solves this problem during development.

这篇关于尝试附加文件℃的自动命名的数据库;文件&gt;失败。具有相同名称的数据库存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆