I have a .NET 4.5 website that uses mysql-connector-odbc-5.1.6-winx64 to communicate with a MySQL 5.5.30(Linux) server. When my host upgraded to Microsoft Windows 2012(IIS 8.5) a difficult bug emerge. This is what the Exception log said :
Faulting application name: w3wp.exe, version: 8.5.9600.16384, time stamp: 0x52157ba0
Faulting module name: myodbc5.dll, version: 5.1.6.0, time stamp: 0x4af34e94
Exception code: 0xc0000005
Fault offset: 0x00018346
Faulting process id: 0x2b8c
Faulting application start time: 0x01d0618edaa07c23
Faulting application path: C:\Windows\SysWOW64\inetsrv\w3wp.exe
Faulting module path: C:\Program Files (x86)\MySQL\Connector ODBC 5.1\myodbc5.dll
Report Id: 206c1036-cd82-11e4-80d8-005056915c0b
Faulting package full name:
Faulting package-relative application ID:
I recreated the exception on my own computer(Windows 8.1(IIS 8.5)). By installing mysql-connector-odbc-5.1.13-winx64
the problem went away. My host can however not upgrade there mysql-connector-odbc-5.1.6 so Im stuck.
The exception is thrown when executing the fill method below
protected int fill(out DataSet ds, OdbcCommand inCommandObj)
{
OdbcDataAdapter dataAdapter;
try
{
ds = new DataSet();
dataAdapter = new OdbcDataAdapter(inCommandObj);
mainConnection.Open();
return dataAdapter.Fill(ds);
}
finally
{
mainConnection.Close();
}
}
This is how the exception looks like
System.AccessViolationException occurred HResult=-2147467261
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=System.Data
StackTrace: at System.Data.Common.UnsafeNativeMethods.SQLGetData(OdbcStatementHandle StatementHandle, UInt16 ColumnNumber, SQL_C TargetType, CNativeBuffer TargetValue, IntPtr BufferLength, IntPtr& StrLen_or_Ind) at System.Data.Odbc.OdbcStatementHandle.GetData(Int32 index, SQL_C sqlctype, CNativeBuffer buffer, Int32 cb, IntPtr& cbActual) at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype, Int32 cb, Int32& cbLengthOrIndicator) at System.Data.Odbc.OdbcDataReader.internalGetString(Int32 i) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap) at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i) at System.Data.Odbc.OdbcDataReader.GetValues(Object[] values) at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values) at System.Data.ProviderBase.SchemaMapping.LoadDataRow() at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at Com.DataAccessLayer.FactoryBase.fill(DataSet& ds, OdbcCommand inCommandObj) in c:\Development\Bradspel Web\Website\App_Code\DataAccessLayer\FactoryBase.cs:line 153
InnerException:
The code that calls the fill method above looks like this
sqlStr = "SELECT r.threadId, r.message, r.createrId, r.createrNickName, t.title, t.description, t.replys, r.createdDate FROM forum_replys r INNER JOIN forum_threads t on(r.threadId = t.id) WHERE t.forumId = 56 and (select mR.id from forum_replys mR WHERE mR.threadId = t.id ORDER BY mR.createdDate ASC limit 1) = r.id ORDER BY t.createdDate DESC limit ?";
commandObj = new OdbcCommand(sqlStr, mainConnection);
commandObj.Parameters.Add("@newsCount", OdbcType.Int).Value = newsCount;
fill(out ds, commandObj);
If I remove the r.message, then everything works just fine. By running the same quary in MySQL Workbench I can see that the message that fails to return looks like this :
'[Pic]http://www.bradspel.net/App_Themes/bradspel/Images/common/gameoftheryear/bestgames.gif[/Pic]<br><br>[R]Årets brädspel 2014 är utsedda! [/R]<br>Tackar alla som hjälpt till att ta fram året brädspel!<br><br>[Pic]http://www.bradspel.net/App_Themes/bradspel/Images/common/gameoftheryear/winners2014.png[/Pic]<br><br>1. [Dead of Winter: A Crossroads Game (2014)]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=150376<br>2. [Splendor (2014)]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=148228<br>3. [Caverna: The Cave Farmers - 2013]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=102794<br>4. [Istanbul - 2014]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=148949<br>5. [Star Wars: Imperial Assault - 2014]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=164153<br>6. [Imperial Settlers - 2014]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=154203<br>7. [Alchemists - 2014]http://www.bradspel.net/sites/bradspel/game/game.aspx?gameId=161970<br><br>[R]Homeland: The Game[/R]<br>[Recension av ConraDargo]http://www.bradspel.net/sites/bradspel/community/communityReplys.aspx?threadId=2501<br><br>[Pic]http://i.imgur.com/nISZpV2.jpg[/Pic]<br>[Youtube länk]https://www.youtube.com/watch?v=DOLG43FCmE0'
The field in the databasetable is set the following way :
message, TEXT,NotNull,default: empty, coolation UTF8(default but are used forSwedish),Engine: INNDB
I have tried to replace the r.message in the SQL query with the message above hardcoded(as message) and this works without problems.
How could I work my way around this problem?