I am creating a new user programmatically (will be adding custom profiles later) and am working on Win2K8 VM:
MembershipUser newUser =
Membership.CreateUser(userNameTxt.Text, passwordTxt.Text, emailTxt.Text);
Roles.AddUserToRole(userNameTxt.Text.Trim(), "Member");
UPDATE:
Connection string:
<remove name="LocalSqlServer" />
<add name="LocalSqlServer"
connectionString="Initial Catalog=MYS;Data Source=WIN2K8;uid=MYS;password=xxxxxx;"
providerName="System.Data.SqlClient" />
Getting the following error:
System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\MYAPP'.
<membership>
<providers>
<remove name="DefaultMembershipProvider"/>
<add
name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<roleManager enabled="true">
You current connection string is this:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer"
connectionString="Initial Catalog=MYS;Data Source=WIN2K8;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
The error here is that you're saying: Connect to my SQL Server database and use the App Pool identity as the 'account' to authenticate my SQL Server db against.
All websites on IIS run under an 'account'. In this case, it looks like this account is called MyApp
.
So the fix you need to have a connection string that says: Don't use whatever 'identity' is setup on this IIS machine, etc. BUT! Use this hardcoded username/password instead.
Check this out, now:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer"
connectionString="Initial Catalog=MYS;Data Source=WIN2K8;uid=username;password=pass;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Take note:
Integrated Security=SSPI;
uid=username;
password=pass;
Just replace the values username
and pass
with the username/password you use to log into your SQL Server database.
Need help learning about what options/keywords you can define in a single connection string? Check this ConnectionStrings site as a reference.
Pro Tip: Instead of <remove name="whatever/>
.. try using <clear/>
eg.
<connectionStrings>
<clear/>
<add name="LocalSqlServer" connectionString="Initial Catalog=MYS;Data Source=WIN2K8;uid=username;password=pass;" providerName="System.Data.SqlClient" />
</connectionStrings>