• Welcome to Valhalla Legends Archive.
 

[Reference] MySql for .NET

Started by MyndFyre, February 09, 2005, 02:02 AM

Previous topic - Next topic

MyndFyre

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)

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 );
}

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

quasi-modo

sweet. I am bookmarking this thread. This might help me in the future.
WAR EAGLE!
Quote(00:04:08) zdv17: yeah i quit doing that stuff cause it jacked up the power bill too much
(00:04:19) nick is a turtle: Right now im not paying the power bill though
(00:04:33) nick is a turtle: if i had to pay the electric bill
(00:04:47) nick is a turtle: id hibernate when i go to class
(00:04:57) nick is a turtle: or at least when i go to sleep
(00:08:50) zdv17: hibernating in class is cool.. esp. when you leave a drool puddle