1

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">
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91
  • would like to see your connection string. sometimes this happens when you use integrated security. have you tried using giving username, password in connection string? – naveen Oct 14 '12 at 12:47
  • No, I haven't. I added connection string to question. – IrishChieftain Oct 14 '12 at 12:52
  • 1
    could you try not giving integrated security and give username password instead? ( sql login ) – naveen Oct 14 '12 at 12:59

4 Answers4

1

System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\MYAPP'.

This indicates that your application pool identity is the virtual account 'IIS APPPOOL\MYAPP'.

You need create a SQL Server login for this identity and add it as a User with appropriate permissions to the Membership database.

Not sure what you mean by create a SQL Server login for "this identity" ...

One way is to use SQL Server Management Studio. Connect "Object Explorer" to your SQL Server instance, click right on "Security / Logins" , select "New Login" and add the login name IIS APPPOOL\MYAPP with Windows Authentication.

Then map this login to a user in the Membership database.

Joe
  • 122,218
  • 32
  • 205
  • 338
1

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:

  1. I've removed the argument: Integrated Security=SSPI;
  2. I've added the argument: uid=username;
  3. I've added the argument: 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>
halfer
  • 19,824
  • 17
  • 99
  • 186
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
  • When I add I get: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty. – IrishChieftain Oct 14 '12 at 13:52
  • *le sigh* ... please note .. that the `` has to come -before- the ``. Why? this says : get rid of -any and all- of the default connections strings ... and now ADD my own. And i'll call it `LocalSqlServer`. – Pure.Krome Oct 14 '12 at 13:55
  • I put it in place of the old remove which was before the add... probably just a side issue anyway. – IrishChieftain Oct 14 '12 at 13:57
  • If it doesn't work, then don't use the Pro tip. Secondly, check the spelling of the `` .. making sure the `name=XXX` is exactly what is being used in the `connectionstrings` and `membership provider`. – Pure.Krome Oct 14 '12 at 14:02
  • Got this connection format to work on my server (but not on my local WIN2K8 VM). Thanks for all your help! – IrishChieftain Oct 14 '12 at 14:49
  • It works on the remote server because that remote server has a locked down IIS, etc. You always need to provide the sql server LOGIN/USER details on a Hosting server which you didn't make. On your -own- local server .. u can use `Integrated Security=SSPI` because that is your own machine and you've logged in as 'YOURSELF' so anything that runs will run 'as you'. There is no 'logged in user' on a remote server. Dude - I really recommend you read up a little bit about basic IIS authentication and what `Integrated Security=SSPI` actually really means. – Pure.Krome Oct 14 '12 at 22:59
  • I understand that under my own logged-in name it should have worked but it didn't. I suspected it had to be something else and that turned out to be the case. The aspnet_SchemaVersions table had no data. Thanks for your help Pure, much appreciated. – IrishChieftain Oct 14 '12 at 23:59
  • Pleasure :) gl! (For the record: Avoid ASP.NET Membership like the plague. Worst thing in the framework, after Entity Framework). – Pure.Krome Oct 15 '12 at 00:15
0

Check with your connection string it should be as shown:

Server=.\SQLEXPRESS;Database=MyDatabase;Integrated Security=SSPI;

Regarding your modified error:

Set enableEventValidation to false and viewStateEncryptionMode to Never as follows:

<pages enableeventvalidation="false" viewstateencryptionmode="Never">
coder
  • 13,002
  • 31
  • 112
  • 214
  • Not using SQLEXPRESS, am using SQL server and connection string is working. – IrishChieftain Oct 14 '12 at 12:28
  • you can find it more detail from here http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx and from here http://msdn.microsoft.com/en-us/library/ms998288.aspx – coder Oct 14 '12 at 12:37
  • Gives 500.19 error and squiglies in config file saying these attributes are not allowed. Am using ASP.NET 4.5 in VS2012. – IrishChieftain Oct 14 '12 at 12:40
  • 1
    Try to watch this video where you need to install some components and then it works fine http://www.youtube.com/watch?v=vBNoTK31zPo or follow this SO Question http://stackoverflow.com/questions/929131/how-do-i-resolve-http-error-500-19-internal-server-error-on-iis7-0 – coder Oct 14 '12 at 12:41
  • Will do. I added those two properties in the page directive but still got the App Pool error. Thanks for your help, I'll watch the video :) – IrishChieftain Oct 14 '12 at 12:45
  • you're welcome hope that helps you in solving your problem :) – coder Oct 14 '12 at 12:45
  • Maybe should have said I am developing on Win2K8 VM – IrishChieftain Oct 14 '12 at 12:47
0

I was able to solve the connection problem by populating the aspnet_SchemaVersions table, per this link:

ASP.NET Membership Error

I was then able to connect locally thus:

<remove name="LocalSqlServer" />
    <add name="LocalSqlServer" 
    connectionString="Initial Catalog=MYS;Data Source=WIN2K8;Integrated Security=SSPI;"
    providerName="System.Data.SqlClient" />
Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91