Exceptions and Linq to Entities -
I have a hard question to ask, please take part with me.
In this code given below, this works because the programmer was interested in presenting specific errors only from the physical data-layer to eventlog. The remaining stack is carried forward, this is especially because it is capable of catching OdbcException ().
I am implementing my membership provider. I am using the links to the units, but I want to send only the low level / physical-level exceptions for the event. Is there any exception that I can catch while using Linq to Entities which will allow me to catch at that level?
As you can see below, even those efforts that have been thrown in the blocked blocks will not be sent for eventlog.
How can this Linq be done with institutions?
code:
public override string ResetPassword (string username, string reply) {if (! EnablePasswordReset) {new NotSupportedException ("password reset is not enabled.") ; } If (Answer == blank & amp;;; &;; required questions and answers) {updateFailureCount (Username, "Password Enter"); New provider throw exceptions ("Password reset is required for password reset."); } String newPassword = System.Web.Security.Membership.GeneratePassword (newPasswordLength, MinRequiredNonAlphanumericCharacters); Valid password accents args = new valid passwordcards (username, new password, true); OnValidatingPassword (args); If (args.Cancel) throw arguments (args.FailureInformation! = Null). File information; And throw a new member designation exception ("Cancel password reset due to password verification failure."); OdbcConnection conn = new OdbcConnection (connectionString); ODBC Commmd CMD = New ODBC Commands ("Select Password Anger, User Lockout User", "Where Username =? And AppNameName =?", Con?); Cmd.Parameters.Add ("Username", OdbcType.VarChar, 255) .Value = Username; Cmd.Parameters.Add ("ApplicationName", OdbcType.VarChar, 255). Valu = pApplicationName; Int rows = 0; String passwordenzer = ""; OdbcDataReader Reader = Faucet; Try {conn.Open (); Reader = CMD Accent Reader (Commandbacks. Singular); If (reader.HasRows) {reader.Read (); If (reader.GetBoolean (1)) new subscription posters throw exceptions ("Available user is locked."); PasswordAnswer = reader.GetString (0); } And {new member designation exception exception ("The available username is not found."); } If (RequiresQuestionAndAnswer & Checkpassword (Answer, Password Enter)) {UpdateFailureCount (Username, "passwordAnswer"); New subscription posters throw exceptions ("wrong password response."); } OdbcCommand updateCmd = New OdbcCommand ("Update users" + "SET password = ?, LastPasswordChangedDate =?" + "Where user name =? And ApplicationName =? And IsLockedOut = False", conn); UpdateCmd.Parameters.Add ("Password", OdbcType.VarChar, 255). Valu = EncodePassword (newPassword); UpdateCmd.Parameters.Add ("LastPasswordChangedDate", OdbcType.DateTime) .Value = DateTime.Now; UpdateCmd.Parameters.Add ("Username", OdbcType.VarChar, 255) .Value = Username; UpdateCmd.Parameters.Add ("@AppName", OdbcType.VarChar, 255). Valu = pApplicationName; Rounds affected = updateCmd.ExecuteNonQuery (); } Hold (OdbcException e) {ifExceptionsToEventLog} {WriteToEventLog (E, "ResetPassword"); New provider throw exceptions (exception messages); } And {throw e; }} Finally {if (reader! = Null) {reader.Close (); } Conn.Close (); } If (affected by rows & gt; 0) {newpassword; } Other {new subscription posters throw exceptions ("user is not found, or user is locked. Password is not reset"); }}
I think I have understood it. With Linq you can catch EntityException with the unit, it will be equal to OdbcException in the above code.
Thank you for anyone who has spent time on this.
Comments
Post a Comment