Valhalla Legends Forums Archive | .NET Platform | [Reference] MySql for .NET

AuthorMessageTime
Myndfyr
MySQL provides a data provider for the ADO.NET system.  Since SMF uses MySQL and I wanted to tie in my message board logins with my ASP.NET 2.0 website, I needed to make my database able to access the MySQL database through ADO.NET.

I discovered this took some tweaking.  Out of the box, you need to remove the TestingFrame folder completely from the code because it relies on a dependency that can't be found.

Also, there is an issue with the way SMF stores dates that are unspecified: it stores them as 0, which is generally like DBNull.  DBNull can't be converted to a DateTime, and SMF will tell you so.  I made the following changes to the code so that an exception wouldn't be thrown, and invalid dates would return DateTime.MinValue instead:
(in the file MySqlDateTime.cs)
[code]
internal MySqlDateTime(DateTime val, MySqlDbType type) : this(type)
{
            if (val == DateTime.MinValue) // this entire conditional and branch were added
            {
                year = 0;
                month = 0;
                day = 0;
                hour = 0;
                minute = 0;
                second = 0;
            }
            else
            { // everything inside this branch constituted the original code.
                year = val.Year;
                month = val.Month;
                day = val.Day;
                hour = val.Hour;
                minute = val.Minute;
                second = val.Second;
            }
        }


/// <summary>Returns this value as a DateTime</summary>
/// <remarks>
/// <para>For invalid dates, this value represents a DateTime that would be equivalent to <b>DateTime.MinValue</b>.</para>
/// </remarks>
public DateTime GetDateTime()
{
            if (!IsValidDateTime)
                // exception thrown is commented out.  instead, return DateTime.MinValue.
                //throw new MySqlConversionException("Unable to convert MySQL date/time value to System.DateTime");
                return DateTime.MinValue;

            return new DateTime( year, month, day, hour, minute, second );
}
[/code]
I also noticed that if you're using .NET 2.0, you need to recompile the assembly; you can't just reference the 1.0 or 1.1 versions (although, oddly enough, from this assembly you can reference the 1.0 or 1.1 version of the CSharpZipLib library that is included).

Hope this helps anyone trying to use MySQL.
February 9, 2005, 8:02 AM
peofeoknight
sweet. I am bookmarking this thread. This might help me in the future.
February 18, 2005, 11:34 PM

Search