-2

I'm building a simple login form using VS2015, C#, SQLite DB and entity Framework (under .net framework 4)

when I enter a valid user and password I get this exception

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in EntityFramework.dll
Additional information: Exception has been thrown by the target of an invocation.

this is my DB :
http://www11.0zz0.com/2016/09/03/23/934209903.png

this is my User Class :
http://www11.0zz0.com/2016/09/03/23/937963117.png

this is the exception :
http://www11.0zz0.com/2016/09/03/23/381133631.png
http://www11.0zz0.com/2016/09/03/23/355831822.png

I tried everything i know .. but i did not succeeded Does any one know how to solve this problem ?

Charaf
  • 177
  • 1
  • 2
  • 12
  • In the 3rd screen shot, the exception has an inner exception. Does the inner exception provide more information? – robor Sep 03 '16 at 21:11
  • @robor78 no .. only this {"Specified cast is not valid."} – Charaf Sep 03 '16 at 21:12
  • this is a guess, change admin.User1.Equals(u) to admin.User1 == u (like you do for the password) – robor Sep 03 '16 at 21:13
  • changing **Equals()** with **==** didn't work – Charaf Sep 03 '16 at 21:15
  • another guess, in DB the password is VARCHAR(50), how long is p = Encryption.SHA1Encode(p) – robor Sep 03 '16 at 21:15
  • In the DB, can the IsAdmin field be null? Are there records in the DB with IsAdmin null? The model requires a non-nullable IsAdmin. – robor Sep 03 '16 at 21:20
  • same probleme when setting the VARCHAR(100) the encrypted password is not that long ... , And No its not null it have a default value '0' – Charaf Sep 03 '16 at 21:25
  • 1
    I'm out of guesses :( Generally "specified cast is not valid" indicates type in database does not match type in model – robor Sep 03 '16 at 21:32
  • Thank you @robor78 .. I'll try to verify the data types – Charaf Sep 03 '16 at 21:43

1 Answers1

1

Finally I found the problem. The type BOOLEAN in SQLite is not very compatible with C# type 'bool' ... I have changed it to int instead and it worked as magic. Thank you mr robor78

Community
  • 1
  • 1
Charaf
  • 177
  • 1
  • 2
  • 12