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);
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. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
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" requires开发者_开发技巧QuestionAndAnswer="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.
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.
While directory permissions, create new user "network service" and configure permissions
Replace |Data directory| to "C:\inetpub\wwroot..."
It is successful.
Running VisualStudio as Administrator solves this problem during development.
Updating the application pool for the Site in IIS Manager to ASP.NET v4.0 solved the issue for me.
精彩评论