Bug #51012 MySQL Connector NET Attempted to read or write protected memory
Submitted: 9 Feb 2010 0:56 Modified: 18 Feb 2010 22:33
Reporter: Michael John Alviz Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:Connector Net 5.2.2 & 6.2.2 OS:Windows
Assigned to: CPU Architecture:Any
Tags: Attempted to read or write protected memory

[9 Feb 2010 0:56] Michael John Alviz
Description:
I am using Visual Studio 2008 SP1, .Net Framework 3.5, MySQL Connector 5.2.2 or 6.2.2 (Tried both connector versions)

The problem occurs when you use the DataSet Designer in VS 2008 to create strongly typed datasets and you happen to create a TableAdapter that refers to a table that returns more than 25 columns/fields. (It can also happen when you try join multiple tables and return several columns/fields).

The DataSet Designer would not be able to create the TableAdapter and instead throw this message: Error Generated Select Statement: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

What is weird about this error is that if I try to create a TableAdapter (using DataSet designer) for tables with lesser columns/fields like 10 or less there is no problem and the designer is able to generate the TableAdapter and all its related queries. Could there be a bug in the MySql Connector NET that creating complex queries or tables with a lot of fields fails?

How to repeat:
How To Repeat:

1. In Visual Studio 2008 add a new DataSet.xsd.

2. In the DataSet designer create a new TableAdapter and choose a table that returns more than 25 fields. (See if the designer can generate the Dataset TableAdapter). Here is where the error is thrown by the designer.

Error Generated Select Statement: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

If you try to create the TableAdapter against a simple table say with with 10 columns/fields it does not error out. Only when there are many fields like > 25.
[11 Feb 2010 8:39] Tonci Grgin
Screen-shot

Attachment: Bug51012.jpg (image/jpeg, text), 72.00 KiB.

[11 Feb 2010 8:45] Tonci Grgin
Hi Michael and thanks for your report.

Unfortunately, I was not able to repeat the problem on my box:
  o SQL: drop table if exists bug51012;
create table bug51012 (Fld1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Fld2 INT, Fld3 INT, Fld4 INT, Fld5 INT, Fld6 INT, Fld7 INT, Fld8 INT, Fld9 INT,
Fld10 INT, Fld11 INT, Fld12 INT, Fld13 INT, Fld14 INT, Fld15 INT, Fld16 INT,
Fld17 INT, Fld18 INT, Fld19 INT, Fld20 INT, Fld21 INT, Fld22 INT, Fld23 INT,
Fld24 INT, Fld25 INT, Fld26 INT, Fld27 INT, Fld28 INT, Fld29 INT);
insert into bug51012 values(NULL, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29);
  o Environment: Remote MySQL server 5.1.40 on OpenSolaris host. c/NET 6.2.2GA. W2K8x64 SP2 client fully updated with SDK. VS2008Pro with VS SDK.

I tried two ways, dropping table from server explorer and adding data adapter with SELECT * sql. Both worked.

Please check your HW and SW environment.
[11 Feb 2010 18:31] Michael John Alviz
I am using MySQL server 5.0.51b by the way do you think I should upgrade?
[11 Feb 2010 22:44] Michael John Alviz
Additional Info:

1. I upgraded to MySql Server 5.1.43 (the latest version) and I still encounter the same problem.
2. I tried creating a new VS project (from scratch/clean solution) and tried creating the new dataset and it sometimes work and sometimes not. What I notice is if I put the Persist Security Info=True in my connection string it was able to create the problematic table. If I remove that it errors out. I tried this on my real/work VS Project and that trick does not work. (connectionstring="user id=xxx;password=xxx;host=xxx;database=xxx;Persist Security Info=True")
3. My real VS Project has already 29 strongly typed DataSets.xsd where in each there maybe around 5 tableadapters or more defined on average for queries and corresponding tables we have on our mysql database.
4. Could it be, that there is a maximum of datasets and table relations and columns that is causing the DataSet Designer to error out? (See #2 where in a clean solution with the persist security info set to true in the connection string works for my bigger table)
5. Here is the schema of the problematic table:
CREATE  TABLE IF NOT EXISTS `MyDatabaseName`.`member` (
  `member_id` INT NOT NULL ,
  `encrypted_id` VARCHAR(200) NOT NULL ,
  `member_status_code` CHAR(3) NOT NULL ,
  `secret_question_code` CHAR(3) NOT NULL ,
  `secret_question_answer` VARCHAR(100) NULL DEFAULT NULL ,
  `user_name` VARCHAR(100) NOT NULL DEFAULT NULL ,
  `password` VARCHAR(200) NULL DEFAULT NULL ,
  `first_name` VARCHAR(100) NULL DEFAULT NULL ,
  `middle_name` VARCHAR(100) NULL DEFAULT NULL ,
  `last_name` VARCHAR(100) NULL DEFAULT NULL ,
  `tax_number` VARCHAR(200) NULL DEFAULT NULL ,
  `address1` VARCHAR(100) NULL DEFAULT NULL ,
  `address2` VARCHAR(100) NULL DEFAULT NULL ,
  `city` VARCHAR(100) NULL DEFAULT NULL ,
  `state` CHAR(2) NULL DEFAULT NULL ,
  `zip` VARCHAR(10) NULL DEFAULT NULL ,
  `day_phone` VARCHAR(100) NULL DEFAULT NULL ,
  `evening_phone` VARCHAR(100) NULL DEFAULT NULL ,
  `email` VARCHAR(100) NULL DEFAULT NULL ,
  `accept_tnc` CHAR(1) NULL ,
  `date_registered` DATETIME NOT NULL ,
  `verified` CHAR(1) NULL ,
  `last_login_date` DATETIME NULL ,
  `login_count` INT NULL ,
  `registering_world_id` INT NOT NULL ,
  PRIMARY KEY (`member_id`) ,
  INDEX FK_as_m (`member_status_code` ASC) ,
  INDEX fk_member_secret_question (`secret_question_code` ASC) ,
  INDEX FK_member_world (`registering_world_id` ASC) ,
  CONSTRAINT `FK_as_m`
    FOREIGN KEY (`member_status_code` )
    REFERENCES `MyDatabaseName`.`member_status` (`member_status_code` )
    ON DELETE restrict
    ON UPDATE restrict,
  CONSTRAINT `fk_member_secret_question`
    FOREIGN KEY (`secret_question_code` )
    REFERENCES `MyDatabaseName`.`secret_question` (`secret_question_code` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_member_world`
    FOREIGN KEY (`registering_world_id` )
    REFERENCES `MyDatabaseName`.`world` (`world_id` )
    ON DELETE RESTRICT
    ON UPDATE RESTRICT)
ENGINE = InnoDB;

Can you please try this table out? Try both connection string settings of where the Persist Security Info is set (true) and one where it is not (false). But still I can only use this approach on a clean/new project but not on my existing project.

I appreciate any feedback. Thanks.
[18 Feb 2010 22:33] Michael John Alviz
I was able to resolve this issue by installing Visual Studio 2008 SP1. I thought I had this VS SP1 already but I misread the VS Help About Info and mistook the SP1 I saw which actually was referring to the .NET Framework 3.5 SP1 and not Visual Studio 2008.

So now I have NET Connector 6.2.2 with VS 2008 SP1 and everything is working fine now. Thanks!
[19 Feb 2010 7:05] Tonci Grgin
Michael, this is the curse of connectors bugs... It can be IDE, connector, OS, server...
Main thing is, problem's solved and you can work.
[6 Dec 2010 19:30] Ferry Wijaya
I have got this problem too, but after i reinstall again my windows that's all work finely. I think this is because an av or the computer was infected by virus.
Thank's