Entity Framework .Net core FindAsync Throw System.OverflowException: Arithmetic operation resulted in an overflow

.net-core asp.net-core-webapi entity-framework-core

Question

I'm trying to create a web API for authentication that return a token. I'm using .Net core 1.1, EF 1.1.0 and SQL 2014 express on Windows 10. I follow direction from this website to create required classes.

In the middleware class, there's a function called GetIdentity to check the username and password in database. Here is the code

private async Task<ClaimsIdentity> GetIdentity(string username, string password, MyDBContext db) {
        try
        {
            m_user SignedUser = await db.Users.FindAsync(username);
            if (SignedUser == null || !SignedUser.password.Equals(password, StringComparison.Ordinal))
                throw new ArgumentException("Invalid username or password");

            return await Task.FromResult<ClaimsIdentity>(
                new ClaimsIdentity(
                    new GenericIdentity(username, "Token"),
                    new Claim[] { }
                ));
        }
        catch (Exception ex) {Console.WriteLine(ex.Message); return await Task.FromResult<ClaimsIdentity>(null); }
    }

When then program hit

m_user SignedUser = await db.Users.FindAsync(username);

It throws System.OverflowException: Arithmetic operation resulted in an overflow.

I didn't get any luck to find the solution or at least the reason why it failed.

Does anyone know why I got that exception?

Thank you for helping me.

P.S: If you need more information, just let me know

1
0
1/21/2017 1:04:52 PM

Popular Answer

I fixed it. I used wrong connection string. I have to put the port number of SQL database in the connection string.

the wrong one:

Server=serverAddress;Database=dbName;User Id=dbUser;Password=dbPassword;

the right one:

Server=serverAddres,portNumber;Database=dbName;User Id=dbUser;Password=dbPassword;

Default MSSQL port number is 1433.

Hope it can help you out if you get same problem with me.

P.S you might get different exception. I got this exception when I tried to run it on VS Code

Like this one:

Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryCompilationContextFactory[1] An exception occurred in the database while iterating the results of a query.

0
1/21/2017 6:10:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow