Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I use zkemkeeper class to connect with fingerprint.

I have a method for synchronize user from fingerprint as follow:

C#
private void SynchronizeUser_Clicked(object sender, EventArgs e) {
            if (currentMouseOverRow >= 0) {
                string Status = Convert.ToString(GVDevices.GetRowCellValue(currentMouseOverRow, "Status"));
                if (Status == "Connect") {
                    axCZKEM1.ReadAllUserID(iMachineNumber);

                    string sdwEnrollNumber = "";
                    string sName = "";
                    string sPassword = "";
                    int iPrivilege = 0;
                    bool bEnabled = false;

                    Dt = new DataTable();
                    StrSQL = "select * from MsEmployee";
                    cldb.sqlSelectReturnDt(StrSQL, Dt);

                    if (Dt.Rows.Count == 0) {
                        StrSQL = "";

                        while (axCZKEM1.SSR_GetAllUserInfo(iMachineNumber, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled)) {
                            StrSQL += "insert into MsEmployee(EmployeeID, EmployeeName) " + System.Environment.NewLine +
                                      "values(" + sdwEnrollNumber + ", '" + sName + "') " + System.Environment.NewLine;
                        }

                        if (cldb.SqlExecuteQuery(StrSQL) == 1) {
                            clglobal.ShowMessage("Success synchronize user.");
                        } else {
                            clglobal.ShowMessage("Fail synchronize user!");
                        }
                    } else {
                        String StrSQLUser = "";

                        while (axCZKEM1.SSR_GetAllUserInfo(iMachineNumber, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled)) {
                            StrSQL = "select * from MsEmployee where EmployeeID = " + sdwEnrollNumber + "";
                            cldb.sqlSelectReturnDt(StrSQL, Dt);

                            if (Dt.Rows.Count > 0) {
                                if (Convert.ToString(Dt.Rows[0]["EmployeeName"]) != sName) {
                                    StrSQLUser += "update MsEmployee set EmployeeName='" + sName + "'" + System.Environment.NewLine +
                                                  "where EmployeeID=" + sdwEnrollNumber + "";
                                }
                            } else {
                                StrSQLUser += "insert into MsEmployee(EmployeeID, EmployeeName) " + System.Environment.NewLine +
                                              "values(" + sdwEnrollNumber + ", '" + sName + "') " + System.Environment.NewLine;
                            }
                        }

                        if (cldb.SqlExecuteQuery(StrSQLUser) == 1) {
                            clglobal.ShowMessage("Success synchronize user.");
                        } else {
                            clglobal.ShowMessage("Fail synchronize user!");
                        }
                    }
                } else {
                    clglobal.ShowMessage("Please connect the device first!");
                    return;
                }
            }
        }


But i have an error like this:
I have a error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

I've also been browsing and found an article to uncheck
"Surpress JIT optimization on module load(Managed only)"
but i can't debug my sourcecode.


Please help me, why this could happen?

Thanks
Posted
Comments
Bernhard Hiller 3-Jun-14 3:05am    
In which line do you get that error?
Is that library a COM library?
Does the application work on 32bit systems?
FX Andy Widjaja 3-Jun-14 3:17am    
in line
while (axCZKEM1.SSR_GetAllUserInfo(iMachineNumber, out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled))

yes, it is a com library
i don't have application work on 32bit systems.


1 solution

Since the call to axCZKEM1.ReadAllUserID(iMachineNumber) did not fail, I guess that iMachineNumber has correct type and value.
The problem likely is in out sdwEnrollNumber, out sName, out sPassword, out iPrivilege, out bEnabled.
What about initializing the strings with new string(' ', 255) or new string('\0', 255)? Also a StringBuilder instead of a string could be appropriate.
Is sdwEnrollNumber really a string?
iPrivilege: what about Int16 or Int64 instead of Int32?
Also old-style libraries often use some kind of integer instead of bool (bool bEnabled).
Of course, any combination of those causes could be possible...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900