none
Attempted to read or write protected memory. This is often an indication that other memory is corrupt. RRS feed

  • Question

  • One of the machines in my office fails with the error in the title when using the following code to access a FoxPro database.

    CODE:

           public Result InsertRow(params)
            {
                Result res = new Result();
                res.Successful = true;
                res.Error = "";
              
                if (_Conn == null)
                {
                    res = CreateConnection();
                    if (!res.Successful) return res;
                }
                else
                {
                    res.Conn = _Conn;
                }

                res.Conn.Open();

                try
                {
                    // First send "set null off" command to VFP so it wouldn't error for missing fields
                    // but instead fill them with empty values if default is not specified
                  
                    OleDbCommand cmdInit = new OleDbCommand("set null off", res.Conn);
                    cmdInit.ExecuteNonQuery();

                    string SQL = "INSERT INTO Fxref (Fxgrp, Fxcov, Fxcd, Fxdeduct, Fxexpire, Fxstmt, Fxsystxt, Fxsysdsc) values (?,?,?,?,?,?,?,?)";
                    OleDbCommand cmd = new OleDbCommand(SQL, res.Conn);
                    OleDbParameter DbFxgrp = cmd.Parameters.Add("Fxgrp", OleDbType.Char);
                    OleDbParameter DbFxcov = cmd.Parameters.Add("Fxcov", OleDbType.Char);
                    OleDbParameter DbFxcd = cmd.Parameters.Add("Fxcd", OleDbType.Char);
                    OleDbParameter DbFxdeduct = cmd.Parameters.Add("Fxdeduct", OleDbType.Char);
                    OleDbParameter DbFxexpire = cmd.Parameters.Add("Fxexpire", OleDbType.Date);
                    OleDbParameter DbFxstmt = cmd.Parameters.Add("Fxstmt", OleDbType.Char);
                    OleDbParameter DbFxsystxt = cmd.Parameters.Add("Fxsystxt", OleDbType.Char);
                    OleDbParameter DbFxsysdsc = cmd.Parameters.Add("Fxsysdsc", OleDbType.Char);

                    DbFxgrp.Value = verifax.Fxgrp;
                    DbFxcov.Value = verifax.Fxcov;
                    DbFxcd.Value = verifax.Fxcd;
                    DbFxdeduct.Value = verifax.Fxdeduct;
                    DbFxexpire.Value = verifax.Fxexpire;
                    DbFxsystxt.Value = ""; // verifax.Fxsystxt; appears to be unused
                    DbFxsysdsc.Value = ""; //appears to be unused

                    string file2read = RTFLocation;
                    string memoContent;
                    using (StreamReader sr = new StreamReader(file2read))
                    {
                        memoContent = sr.ReadToEnd();
                    }
                    DbFxstmt.Value = memoContent;

                    // insert the record
                    cmd.ExecuteNonQuery();
                    res.Conn.Close();
                }
                catch (Exception ex)
                {
                    if (res.Conn != null) res.Conn.Close();
                    res.Error = ex.Message;
                    res.Successful = false;
                }
                finally
                {
                    if (res.Conn != null) res.Conn.Close();
                }

                return res;
            }

    What could possibly be a solution?  Perhaps we should just try to reinstall .net 2.0?
    Tuesday, September 11, 2007 3:38 PM

All replies

  • Do you know where it is doing this?  Is it the streamreader or referencing verifax, is it using cmdInit or res?  There are quite a few places where null values could be getting dereferenced here.  If you could provide the line that is throwing this error it would help us to figure out how to fix this one in particular.

    Tuesday, September 11, 2007 6:35 PM
  • John,

    I will look into it this next week.

    Thanks for taking your time,
    Nate
    Friday, September 14, 2007 10:22 PM