0

There is hosting issue of an application on IIS server made in .NET Core MVC using the Microsoft.AspNetCore.Identity.EntityFramework package that manages roles. Here we are getting an error that a particlar table/obj (AspNetUser) made by IdentityManager is invalid, but the DB and tables exist.

try
{
    var signInResult = await signInManager.PasswordSignInAsync(loginRequest.Username, loginRequest.Password, false, false);


    if (signInResult != null && signInResult.Succeeded)
    {
        if (!string.IsNullOrWhiteSpace(loginRequest.ReturnUrl))
        {
            return Redirect(loginRequest.ReturnUrl);
        }
        return RedirectToAction("Index", "Home");
    }
}
catch (Exception ex)
{
    System.Diagnostics.Debug.Write(ex.ToString());
}

This is what we tried error we are getting in the first line of try block i.e. signInResult.

Error Screenshot

Database Table

Connection String

  • can you post the error you're getting ? – federico scamuzzi Jul 25 '23 at 07:18
  • **Microsoft.Data.SqlClient.SqlException: 'Invalid object name 'AspNetUsers'.'** @federicoscamuzzi this is error – Pranav Nigam Jul 25 '23 at 07:25
  • Maybe relevant: https://stackoverflow.com/questions/38040976/invalid-object-name-dbo-aspnetusers-in-asp-net-mvc-5-entity-framework – Tao Gómez Gil Jul 25 '23 at 07:28
  • @TaoGómezGil thanks for your reply but no solution from the above link worked for me. – Pranav Nigam Jul 25 '23 at 07:44
  • Are you using Code First Migrations? https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/ – Tao Gómez Gil Jul 25 '23 at 07:56
  • can you post also your appsettings? .. double check the connectionstring .. i'm pretty sure it can't connect to the databse .. or on the wrong db ..check if you have other appsetitngs.ENV.json ... maybe in there there is another connectionstring .. if nothing work ..check the app pool identity – federico scamuzzi Jul 25 '23 at 08:15
  • @TaoGómezGil yes I am using Code First Migration. Is there a different way to publish such applications on IIS? – Pranav Nigam Jul 25 '23 at 09:05
  • As said in other comments, the error suggest that the table AspNetUsers does not actually exist. It could be that you are targetting the wrong database, or that it exists in another schema... I suggest that you delete the database and let it be recreated and updated by the Code First Migrations. – Tao Gómez Gil Jul 25 '23 at 09:10
  • @TaoGómezGil I deleted all the migration files and the database, again ran the migration and updated database from scratch still same error occurred. The database I am targeting is correct and the schema is also correct. – Pranav Nigam Jul 25 '23 at 09:35
  • Does this error only appear on iis? and does this error occur when running locally? – samwu Jul 26 '23 at 08:54
  • @samwu the the application runs perfectly ok when I am trying to run from Visual Studio 2022 but after publishing and running it on IIS the error occurs. – Pranav Nigam Jul 26 '23 at 09:42

1 Answers1

0

Solution

Thank you all for your valuable responses and support throughout this troubleshooting process. I sincerely appreciate your time and effort in helping me resolve the issue.

After carefully reviewing the situation, I realized that the problem was caused by having two separate databases with different connection strings. To rectify this, I decided to delete both databases and all migration files. Instead, I created a single database containing all the necessary tables.

As a result, the application is now functioning flawlessly, and the login process is working perfectly fine.

Once again, I am grateful for your assistance and kindness. Your contributions were instrumental in finding the solution. Thank you!