• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1112
  • Last Modified:

"Attempted to read or write protected memory" exception

I am importing into my database using my own tool (c#) in an ASP.NET app.  The tool works fine in a development environment, but fails when I run on a non-development server.  I get the "Attempted to read or write protected memory" exception when I do the database update.  This error makes no sense to me.

This only happens when I import Japanese characters.

I am using the same machine to run the app, and teh same database.  The column being loaded is a nvarchar type.  The only difference is the web server.  The web.config is the same for both configs.

Help!
0
No1Coder
Asked:
No1Coder
  • 14
  • 10
  • 3
  • +3
1 Solution
 
waltersnowslinarnoldCommented:
Access to that part from the current app location is not prompted. that may be the issue with your regard..
0
 
No1CoderAuthor Commented:
That comment makes no sense.
0
 
swapneel_d14Commented:
Could you post your update query here adn well as comepleet Stack  trace..

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
No1CoderAuthor Commented:
update sql:
select * from project where proj_id = -1

Exception:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Data.Common.UnsafeNativeMethods

Stack:
at System.Data.Common.UnsafeNativeMethods.ICommandText.Execute(IntPtr pUnkOuter, Guid& riid, tagDBPARAMS pDBParams, IntPtr& pcRowsAffected, Object& ppRowset) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at System.Data.Common.DbDataAdapter.UpdateRowExecute(RowUpdatedEventArgs rowUpdatedEvent, IDbCommand dataCommand, StatementType cmdIndex) at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataTable dataTable) at TrackStar.Objects.Database.updateTable(DataTable tbl, String sql) in D:\Projects\TrackStar\TrackStar 9.3\Objects\Database.cs:line 279 at TrackStar.Controls.ucImport.update() in D:\Projects\TrackStar\TrackStar 9.3\Base\ucImport.ascx.cs:line 1707  
 
 
0
 
swapneel_d14Commented:
then Try to resintalling Dotnet Framework.

regards
0
 
No1CoderAuthor Commented:
I see this error on multiple servers (Windows 2005, and Windows 2008).  This is .net 2.0 if it matters.
0
 
swapneel_d14Commented:
I don't think server version is issue. as you have stated that you are running application from same
machine and on same database and Same tool is working fine on development server.

Reinstall  framework and service pack on your non develoment service and then re -deploy your tool.

else could you post recent steps you have taken to resolve your problem  that might provide us Clue.
0
 
No1CoderAuthor Commented:
I mentioned the servers because these are the ones hosting the asp.net application.  My development environment is a local web server on a vista machine.

Reloading the frameworkd would make sense to me if it failed on one server, but not if it is failing on multiple servers on different os versions.

Both servers are set for auto update, so they should have the most current service packs.

Regarding steps, I really don't know what to do with this one.  That is why I posted.  Since it doesn;t fail in development, I cant setp through it.  It put a try/catch around the update statement to be sure I was in the correct place in the code.  I printed the stack and exception details (above) in the catch event.  The same code works find if there are no Japanese characters in the import.
Here is the import (from a tab-delimited file).  The spanish (line 1) works fine.  Japanese characters fail.

HR Event      Description
Capacitación      Capacitación de empleado
¿¤à·üÈ      ¿¤à·üÈ
0
 
swapneel_d14Commented:
Can you pleas Check and verify regional settings (under Control Panel) on development  machine and on hosted Server that they are identical.

check out below links for reference

http://www.emeditor.com/help/glossary/systemdefaultencoding.htm

http://startbigthinksmall.wordpress.com/2009/01/20/utf8encodingdefault-encodingutf8-net-c/

http://msdn.microsoft.com/en-us/library/system.text.unicodeencoding.aspx
0
 
swapneel_d14Commented:
if you find any difference in settings and wanna amend regional settings then

Follow Steps in greggman  as below

http://www.greggman.com/japan/xp-ime/xp-ime.htm
0
 
No1CoderAuthor Commented:
The UI for the vista development machine is very different from the asp.net server, but both are set to us/english, etc.  Default values for us install.

I have the value 10001 checked on the language tab on the server.

I installed a code snip whwere I am encoding the downloaded file.
HttpFileCollection allFiles = Page.Request.Files; 
if (allFiles.Count == 0) return null;
HttpPostedFile uploadedFile = allFiles[0];
if (uploadedFile.ContentLength == 0) return null;
string filename = uploadedFile.FileName;
FileInfo f = new FileInfo(filename);
filename = f.Name;
	
BinaryReader br = new BinaryReader(uploadedFile.InputStream);
byte []buffer = new byte[uploadedFile.InputStream.Length];
buffer = br.ReadBytes((int)uploadedFile.InputStream.Length);
//------------------------------------------------------------
// if you save a file as a Unicode Text file, it will contain
// the two-byte header with the values below.
//------------------------------------------------------------
if (buffer.Length >= 2 && buffer[0] == 255 && buffer[1] == 254)
{
    UnicodeEncoding ue = new UnicodeEncoding();
    string unicode = ue.GetString(buffer, 0, buffer.Length);
   return unicode;
  }          }

Open in new window

0
 
swapneel_d14Commented:
Just to confirm
1] japnese chracters does process successfully on developemnt  machine..?

2] The only differnce is LocalHost server / WebServer where as source Code and database are same.
in both processing?  isnt it?


0
 
No1CoderAuthor Commented:
Yes to both.

I was checking the properties page of the project to verify that I am using the local web server.  I am.

I noticed that the app was targeting .Net 3.5, which was a mistake.  I changed it to 2.0, and recompiled and deployed.  It didn't make any difference.
0
 
swapneel_d14Commented:
Ok.   After app file chnages to 2.0 - is it same error msg - Attempted to read or write protected memory"
exception?   Can you post your Update sql code or code block for above exception?

I dont think Code amendment is required as it is working on LocalHost - Have u tried  to use UTF32Encoding for Japnese?

0
 
No1CoderAuthor Commented:
I don;t know if the code will help but it is below.  The "setwarning" displayed the error message on the screen.

After changing to 2.0, error is the same.  

I have not tried utf32, and don't understand why I need to.  The error is with the database update.  It doesn't make any sense to me.  Everything is teh same except the web server.  The local one on vista works.  The ones I've tries on w2005 & w2008 both fail.  COuldthere be something in the asp.net configuration that is different on the os's?  I haven;'t changed any of the files.  Fresh installation on w2008.
 //---------------------------
 // now perform the update...
 //---------------------------
 int rowcount = Database.updateTable(update, sql);
  Utility.eventLog(getUser().ID,LogEntryType.DataImport, added.ToString() + " rows added and " + updated.ToString() + " updated in " + table + " via import");
 }
 else
 {
     int rowcount = Database.updateTable(t, sql);
     Utility.eventLog(getUser().ID, LogEntryType.DataImport, rowcount.ToString() + " rows added in " + table + " via import");
                    }
                } 
catch (Exception ex) 
{
setWarning(LabelError,  Resources.Errors.warn189, ex.Message);
return false;
}
	

Open in new window

0
 
swapneel_d14Commented:
yah.

what is this Database.updateTable
0
 
No1CoderAuthor Commented:
my low level update method.  See code.
   static public int updateTable(DataTable tbl, OleDbCommand cmd)
        {
            OleDbConnection connection = Connect();
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            cmd.Connection = connection;
            adapter.SelectCommand = cmd;

            OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter);
            int rows = adapter.Update(tbl);
            disconnect(connection);
            return rows;
        }

Open in new window

0
 
swapneel_d14Commented:
Do you have Same Antivirus application installed on LocalHost and  Production Web Server

Uninstall it and try.
0
 
No1CoderAuthor Commented:
no anti virus on either machine
0
 
swapneel_d14Commented:
Ok . can you try using begin transaction and commit transaction for update block

and also post your update SQl statement.
 is it A Stored procedure??
0
 
No1CoderAuthor Commented:
The updatetable method (above) is used for the update.  The sql used in the update method follows:
"select * from project where proj_id = -1"

There is only one row in the table being updated.  The update statement is generated by the OldDBDataAdaptor (I assume).  I do not have access to it.

In my develoment environment, I changed to use the Visual Studion Development Server.  This worked okay.  When I change to use the remote server, it fails.  I was unable to get remote debugging working (who can figure that stuff out?), so more info in not available.

I don't understand the begin transaction comment.  I am not using explicit transaction controls in my app.
0
 
No1CoderAuthor Commented:
additional info...The field containing the japanese characters has a unique constraint on it.  I tried updating a different field without the unique constraint...It still fails.
0
 
Eugene ZCommented:
you got the error when you run update from .net apps not from sql server ssms. correct?
you need patch and configure sql server, VS.NET, etc
check solution from :


http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6adca20b-649f-41a4-8fa1-09534882d76chttp://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6adca20b-649f-41a4-8fa1-09534882d76c

---
after all - check  and post your server\PC event viewer errors , sql server error log (BTW - what version\edition do you run - sql server VS.net?),

0
 
Bob LearnedCommented:
If nobody has said this, that error is a bug in the some part of the framework or underlying data provider, including MDAC.

The first thing that I see is that the database is unclear, and if you are using SQL Server, then I am curious why use the OleDb stuff?
0
 
No1CoderAuthor Commented:
I am using VS 2008 (SP1)

I use oledb because I originally intended teh app to run on sql or oracle.

I can't fine a solution in the cases above.  I don;t think they apply.

The update code is in prior comments.  Updating from .net app.

If there is a bug, is there a fix?
0
 
Bob LearnedCommented:
1) The exact fix depends on knowing more detail than we have.

2) I would start by looking at the differences in MDAC versions.

3) Also, there are ways to have a generic data layer, without using OLE DB.

4) If you are working with SQL Server, then I would use System.Data.SqlClient.

5) If you are working with Oracle, then I would use the Oracle Data Provider from Oracle (and not Microsoft).
0
 
No1CoderAuthor Commented:
To:  The learnedone

I have provided a tremendous amount of detail over several weeks on this issue.  Do you have a specific quesition?  I will answer it.

Its nice that you want me to redesign my application data layer.  Perhaps that is needed, but all I want is a fix for tihs problem.

I don't know anything about MDAC.

If you guys can't help me them I am wasting my time with this service,
0
 
MogalManicCommented:
What version of mdac are you using?

Here is how you find out:
http://support.microsoft.com/kb/301202
0
 
Bob LearnedCommented:
You need to remember that sometimes finding the exact problem is like trying to find a needle in a haystack.  You have spent a lot of time providing detail, but I believe that source of the problem will not be easy to find.  

MDAC versions can be different between different operating systems, so it is a logical first step to check.  Another option is .NET framework service packs, but you already mentioned that you are using 2008 SP1.  Another option is examining the way that you are using the code.

The .NET data providers follow a pattern, and switching out OleDb with Sql prefixes should be a simple replace in the project/solution.

I have worked with E-E for 10 years from the answering side, so I am always curious about the expectations that askers to get their every question answered.   You might have pay for the service, but the experts donate their time.  
0
 
MogalManicCommented:
I agree with TheLearnedOne.  The OleDb database providers are not guaranteed to be the most current and bug free as the Native .net providors (System.Data.SqlClient for SQL Server and System.Data.OracleClient for Oracle). OleDb  part of the Microsoft Data Access Components (MDAC) stack. There has been many versions of MDAC.
http://msdn.microsoft.com/en-us/library/ms810805.aspx

If at all possible I would use the specific providors for the database.  If you want to keep your implementation of the DAL database agnostic, you can use the ProvidorFactory API as described here:
http://www.codeproject.com/KB/vb/ProviderIndependentCode.aspx

0
 
No1CoderAuthor Commented:
I created a data access layer using SqlClient, and implemented it only for the import function that was failing.  This solved the problem.

My whole application is built on OleDB.  Am I likely to encounter problems if I switch the whole thing?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 14
  • 10
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now