Dot Net Nuke – A critical error has occurred. An unexpected error has occurred

Some of you might have seen this error after upgrading your DNN from v6 to v7.  It’s a bit scarey because it means that no-one can log into your DNN instance, not even a super user.  Troubleshooting must therefore begin on the hosting server.  Check out the log files under .Portals_defaultLogs.  For me the critical error was:

2013-08-23 17:09:52,491 [hub][Thread:14][ERROR] DotNetNuke.Services.Exceptions.Exceptions – ~/Default.aspx?tabid=126&error=An unexpected error has occurred
System.ArgumentException: Parameter count does not match Parameter Value count.
at Microsoft.ApplicationBlocks.Data.SqlHelper.AssignParameterValues(SqlParameter[] commandParameters, Object[] parameterValues)
at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(String connectionString, String spName, Object[] parameterValues)
at DotNetNuke.Security.Membership.Data.SqlDataProvider.UpdateUser(Int32 userId, Int32 portalID, String firstName, String lastName, Boolean isSuperUser, String email, String displayName, Boolean updatePassword, Boolean isApproved, Boolean refreshRoles, String lastIpAddress, Boolean isDeleted, Int32 lastModifiedByUserID)
at DotNetNuke.Security.Membership.AspNetMembershipProvider.UpdateUser(UserInfo user)
at DotNetNuke.Entities.Users.UserController.UpdateUser(Int32 portalId, UserInfo user, Boolean loggedAction, Boolean clearCache)
at DotNetNuke.Entities.Users.UserController.UserLogin(Int32 portalId, UserInfo user, String portalName, String ip, Boolean createPersistentCookie)
at DotNetNuke.Modules.Admin.Authentication.Login.ValidateUser(UserInfo objUser, Boolean ignoreExpiring)
at DotNetNuke.Modules.Admin.Authentication.Login.UserAuthenticated(Object sender, UserAuthenticatedEventArgs e)
at DotNetNuke.Modules.Admin.Authentication.Login.OnLoginClick(Object sender, EventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The error mentions a mismatch between passed parameters and those that are expected, ie:

at DotNetNuke.Security.Membership.Data.SqlDataProvider.UpdateUser(Int32 userId, Int32 portalID, String firstName, String lastName, Boolean isSuperUser, String email, String displayName, Boolean updatePassword, Boolean isApproved, Boolean refreshRoles, String lastIpAddress, Boolean isDeleted, Int32 lastModifiedByUserID)

So first place to look is at the Stored Procedure called UpdateUser and see what it’s expecting.  You can do this in SQL Server Management Studio, navigate to your DB, open programmability and expand Stored Procedures.  Down towards the bottom is a SP called dbo.UpdateUser.  Right click on it and select Modify and you can see the guts of what it does:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UpdateUser]
@UserID         int,
@PortalID        int,
@FirstName        nvarchar(50),
@LastName        nvarchar(50),
@IsSuperUser    bit,
@Email          nvarchar(256),
@DisplayName    nvarchar(100),
@VanityUrl        nvarchar(100),
@UpdatePassword    bit,
@Authorised        bit,
@RefreshRoles    bit,
@LastIPAddress    nvarchar(50),
@passwordResetToken uniqueidentifier,
@passwordResetExpiration datetime,
@IsDeleted        bit,
@LastModifiedByUserID int
AS
UPDATE dbo.Users
SET
FirstName = @FirstName,
LastName = @LastName,
IsSuperUser = @IsSuperUser,
Email = @Email,
DisplayName = @DisplayName,
UpdatePassword = @UpdatePassword,
PasswordResetToken=@passwordResetToken,
PasswordResetExpiration=@passwordResetExpiration,
LastIPAddress = @LastIPAddress,
LastModifiedByUserID = @LastModifiedByUserID,
LastModifiedOnDate = getdate()
WHERE  UserId = @UserID

IF @PortalID IS NULL
BEGIN
UPDATE dbo.Users
SET
IsDeleted = @IsDeleted
WHERE  UserId = @UserID
END
ELSE
BEGIN
UPDATE dbo.UserPortals
SET
Authorised = @Authorised,
RefreshRoles = @RefreshRoles,
VanityUrl = @VanityUrl,
IsDeleted = @IsDeleted
WHERE  UserId = @UserID
AND PortalId = @PortalID
END

If you look closely you’ll see a few extra parameters included in addition to those shown in the original error message:

Stored Procedure Query Error
@UserID         int, Int32 userId
@PortalID int, Int32 portalID
@FirstName nvarchar(50), String firstName
@LastName nvarchar(50), String lastName
@IsSuperUser    bit, Boolean isSuperUser
@Email          nvarchar(256), String email
@DisplayName    nvarchar(100), String displayName
@VanityUrl nvarchar(100),
@UpdatePassword bit, Boolean updatePassword
@Authorised bit, Boolean isApproved
@RefreshRoles bit, Boolean refreshRoles
@LastIPAddress nvarchar(50), String lastIpAddress
@passwordResetToken uniqueidentifier,
@passwordResetExpiration datetime,
@IsDeleted bit,
@LastModifiedByUserID int Int32 lastModifiedByUserID

To get things back up and running I removed all instances of these ‘extra’ parameters from the Stored Procedure and submitted the changes (Query -> Execute menu item).  My updated Stored Procedure was:

USE [DB NAME]
GO
/****** Object:  StoredProcedure [dbo].[UpdateUser]    Script Date: 08/23/2013 17:23:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UpdateUser]
@UserID         int,
@PortalID        int,
@FirstName        nvarchar(50),
@LastName        nvarchar(50),
@IsSuperUser    bit,
@Email          nvarchar(256),
@DisplayName    nvarchar(100),
@UpdatePassword    bit,
@Authorised        bit,
@RefreshRoles    bit,
@LastIPAddress    nvarchar(50),
@IsDeleted        bit,
@LastModifiedByUserID int
AS
UPDATE dbo.Users
SET
FirstName = @FirstName,
LastName = @LastName,
IsSuperUser = @IsSuperUser,
Email = @Email,
DisplayName = @DisplayName,
UpdatePassword = @UpdatePassword,
LastIPAddress = @LastIPAddress,
LastModifiedByUserID = @LastModifiedByUserID,
LastModifiedOnDate = getdate()
WHERE  UserId = @UserID

IF @PortalID IS NULL
BEGIN
UPDATE dbo.Users
SET
IsDeleted = @IsDeleted
WHERE  UserId = @UserID
END
ELSE
BEGIN
UPDATE dbo.UserPortals
SET
Authorised = @Authorised,
RefreshRoles = @RefreshRoles,
IsDeleted = @IsDeleted
WHERE  UserId = @UserID
AND PortalId = @PortalID
END

After updating this you should be able to once again log in to your DNN portal.  Enjoy……

8 thoughts on “Dot Net Nuke – A critical error has occurred. An unexpected error has occurred”

  1. Thanks for the hint. Did you ever figure out the cause of this error, respectively why the stored procedure is wrong?

  2. Thanks for this article. It isn’t the full solution, but it helped me figure out the underlying problem. The actual issue is that the AspNetMembershipProvider was moved to a different DLL in DotNetNuke 7, but the upgrade wizard does not remove the old version, and it does not update the web.config.

    I wrote about the solution here: http://kevinlawry.wordpress.com/2014/02/11/fix-for-login-error-after-dnn-7-upgrade/

    I hope it helps someone else. I was beating my head against a wall for hours, so maybe we can save someone else some grief.

  3. I’m experiencing the same issue after upgrading from DNn 7.0.x to 7.2.2,,, I checked my AspNetMembershipProvider entry in web.config, it seems OK?

    any idea how to fix this? tx

Leave a Reply