MySQL
MySQL Connector/Net 6.3.0 alpha 1 has been released
MySQL Connector/Net 6.3.0, a new version of the all-managed .NET driver
for MySQL has been released. This is an alpha release and is intended to
introduce you to the new features and enhancements we are planning. This
release should not be used in a production environment.
It is now available in source and binary form from
[http://dev.mysql.com/downloads/connector/net/6.3.html] and mirror sites
(note that not all mirror sites may be up to date at this point of time
- if you can’t find this version on some mirror, please try again later
or choose another download site.)
New features or changes:
- Visual Studio 2010 RC support
- Nested transaction scope support
What we know may be broken
- Documentation is not updated yet and is not integrated into VS 2010
- Data editing view (in VS) does not function in this build
Please let us know what else we broke and how we can make it better!
Come see what’s new with 6.2
This Thursday (1/21) we will be hosting a webinar where we go over the new features in Connector/Net 6.2. You can get more information and register for the webinar here.
MySQL Embedded and Windows webinar coming up
One of the best kept secrets in the MySQL world are the terrific (and free) webinars that are available. In fact we have just such a webinar coming up this Thursday. This one is covers using MySQL embedded with Windows and is presented by Mike Frank. You can find out more and register here.
It’s free and I know you can spare an hour so what are you waiting for?
Tracing changes in MySQL Connector/Net 6.2 – Part 2
In our last installment we found our hero investigating the tracing changes found in Connector/Net 6.2. This time we’ll take a closer look at the format of the trace data and how developers can use that information to write new and interesting trace listeners.
Understanding the plumbing
The first thing we need to understand is a little about how the trace messages are routed. The main method we are interested in is TraceSource.TraceEvent. Here is the signature.
public void TraceEvent(
TraceEventType eventType,
int id,
string format,
params Object[] args)
All the other TraceSource methods like TraceInformation eventually boil down to a call to TraceEvent. TraceEvent will run through all the attached listeners and call the TraceEvent method on each.
The default behavior of listeners is to eventually call String.Format using the format given. It plugs the parameters in and comes out with a string that can be sent to the console, to a file, or some other output. Thankfully Microsoft saw fit to make TraceEvent virtual allowing derivative listeners to override and do interesting things.
How we use TraceEvent
Here is the signature for TraceListener.TraceEvent.
public virtual void TraceEvent(
TraceEventCache eventCache,
string source,
TraceEventType eventType,
int id,
string format,
params Object[] args)
eventCache is provided by the framework and contains information such as process id, thread id, timestamp, etc.
source is the name of the TraceSource that provided the event
eventType is the .NET defined type of this event. This can have values such as Information, Warning, Error, etc.
id is the application provided event id. This value is application defined and we’ll explain how we use it later in this post.
format is the parameters string message that listeners such as ConsoleTraceListener would use for output
args is the array of arguments available to plug into the format string. This is the actual data for the event.
The key to using the data provided in TraceEvent is simply to know that the data always comes in a specific order and format. The following information only applies to events coming from the mysql source. The eventCache, source, eventType, and format parameters are self explanatory so we’ll start with id.
The id parameter is our MySql-centric event id. We wanted to give very specific information about the type of event. We have a public enum available in the 6.2 assembly called MySqlTraceEventType. Here is the definition.
public enum MySqlTraceEventType : int
{
ConnectionOpened = 1,
ConnectionClosed,
QueryOpened,
ResultOpened,
ResultClosed,
QueryClosed,
StatementPrepared,
StatementExecuted,
StatementClosed,
NonQuery,
UsageAdvisorWarning,
Warning,
Error
}
Before we talk about the event-specific data points, let me mention about a small problem we needed to solve. We wanted to have a numeric id attached to each event that would allow all the events belonging to a given query to be gathered together. The only way we could accomplish that was to use a counter that gets incremented each time a driver is opened. (remember we needed a value that is unique on the same thread so we can’t use process id, thread id, or event MySQL server thread id). We’ll call this the driver id and every event that comes from the mysql source has this driver id as the first member in the args array.
Here’s a table that lists each mysql event and what the arguments array looks like. Please keep in mind that these arguments start in the second element (index == 1)
| Event | Arguments |
| ConnectionOpened | connection string |
| ConnectionClosed | <none> |
| QueryOpened | mysql connection id, query text |
| ResultOpened | field count, affected rows (-1 if select), inserted id (-1 if select) |
| ResultClosed | total rows read, rows skipped, size of resultset (in bytes) |
| QueryClosed | <none> |
| StatementPrepared | prepared sql, statement id |
| StatementExecuted | statement id, mysql server thread id |
| StatementClosed | statement id |
| NonQuery | <varies> |
| UsageAdvisorWarning | usage advisor flag (see below) |
| Warning | level, code, message |
| Error | error number, message |
Here’s the definition of the publicly available UsageAdvisorWarningFlags enum.
public enum UsageAdvisorWarningFlags
{
NoIndex = 1,
BadIndex,
SkippedRows,
SkippedColumns,
FieldConversion
}
So that’s it. This information will be documented and may change slightly as we find problems. In fact we’ve already identified a small issue and may add a “current database” parameter to the connection opened event since the current database can be different than what is set on the connection string. Be sure, when we make these changes they’ll be documented and by checking the version of the assemblies involved you can do the right thing.
Armed with this information you should be able to go forth and make very interesting trace sniffing apps for MySQL. If you accept such a challenge, drop me a line. I would love to know what you think!
Tracing changes in MySQL Connector/Net 6.2 – Part 1
For years, Connector/Net has been a key part of any MySQL & .NET developer’s toolbox. Tracing is also a key part of a developer’s life and Connector/Net has always output trace messages.
This first post is a review of .NET tracing systems and how we changed our trace output. The second post will cover how developers can use the new tracing format to develop new applications.
Tracing in .NET 1.x
.NET shipped with a very simple tracing system. You have a static class named Trace that has static methods such as Write and WriteLine. An application can use code like the following to output a message to the trace log.
Now that we have output our message, how do we direct it somewhere? You do that with listeners. There are a few standard listeners included in the framework (ConsoleTraceListener, XmlTraceListener, EventLogTraceListener) but you are free to create your own. You can attach a listener at runtime or via an application configuration file. There’s no need to show you how that is done. You can easily find it on the web. What we really want to talk about are changes in .NET 2 tracing and how Connector/Net makes use of it.
Tracing in .NET 2.x
Developers usually want to just trace a particular part of an application. They may just want to get the network tracing or maybe just the file I/O. To accommodate this, Microsoft created a new class named TraceSource. You can really think of it as just a Trace class with a name. Now when you add listeners via the config file you have to add them to a source with a particular name. Here’s what it might look like.
<configuration>
<system.diagnostics>
<sources>
<source name="TraceTest" switchName="SourceSwitch"
switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="console" />
<remove name ="Default" />
</listeners>
</source>
</sources>
<switches>
<!-- You can set the level at which tracing is to occur -->
<add name="SourceSwitch" value="Warning" />
<!-- You can turn tracing off -->
<!--add name="SourceSwitch" value="Off" -->
</switches>
<sharedListeners>
<add name="console"
type="System.Diagnostics.ConsoleTraceListener"
initializeData="false"/>
</sharedListeners>
</system.diagnostics>
</configuration>
You can also specify a switch level, a filter level, and trace options (like should the output include process id, thread id, timestamp, etc).
Starting with Connector/Net 6.2, we have started using TraceSource to output our trace data. Our source is named, cleverly enough, mysql.
Using the mysql trace source
Using our new tracing is very simple. Just use a configuration block similar to what I have above except use “mysql” as the name of the source instead of “TraceTest”. One question you may have, though, is how to add listeners to our source at runtime. You do that with the new MySqlTrace class. Here’s how.
MySqlTrace.Listeners.Add(new ConsoleTraceListener());
Difference is in the details
We’ve also increased the level of detail included in our trace messages. Each trace message includes a counter value that attaches it to other trace messages belong to the same connection. We did this to enable the development of applications such as a powerful log viewer that will also serve as a visual trace listener. With this app, a developer would be able to query the log output for various scenarios. Examples would be “show me all queries where all the rows were not read
So where to from here?
There’s much more to say about our new trace output and, in my next post, I’ll go into the exact format of the data, and we (and you) can use that data to create new and exciting trace listeners.
MySQL Connector/Net 6.2.2 GA has been released
MySQL Connector/Net 6.2.2, a new version of the all-managed .NET driver for MySQL has been released.This is our latest GA release and is suitable for use in all scenarios against servers ranging from version 4.1 to 5.4!
It is now available in source and binary here and mirror sites (note that not all mirror sites may be up to date at this point of time – if you can’t find this version on some mirror, please try again later or choose another download site.)
The new features or changes in this release are:
- Connection pool cleanup timer. We now utilize a timer that cleans idle connections that are no longer connected every 3 minutes
- We are now using stream and TCP-based timeouts to handle command timeouts. This is more inline with what SqlClient does and should be more reliable than our old timer based approach
- Completely refactored MySqlConnectionStringBuilder
- We now support the TableDirect query type
- Completely refactored our logging system. Our trace data is now published using TraceSource and has a specific format so to allow third party listeners to be created.
- Lots of bug fixes
Please let us know what else we broke and how we can make it better!
Webinar on migrating SQL Server to MySQL
We have an exciting webinar coming up tomorrow (12/15) on migrating from SQL Server to MySQL. LiveTime Software is a leader in ITIL service management and help desk products. They have started offering a free migration service and this webinar will go over everything from toolsets used to character sets.
You can read more about it and register for this webinar here. So I know you have an hour you can spare and when it comes time to renew that SQL Server license you’ll be glad you did.
MySQL Connector/Net 6.1.3 has been released
MySQL Connector/Net 6.1.3, a new version of the all-managed .NET driver for MySQL has been released. This is our latest GA release and is suitable for use in all scenarios against servers ranging from version 4.1 to 5.4!
It is now available in source and binary form from [http://dev.mysql.com/downloads/connector/net/6.1.html] and mirror sites (note that not all mirror sites may be up to date at this point of time – if you can’t find this version on some mirror, please try again later or choose another download site.)
This release builds on the cool new features introduced with 6.1.2 and adds the following changes/bugfixes.
- fixed session state provider table definition to allow more than 64K per-session data (bug#47339)
- fixed compilation problem in NativeDriver inside ExecuteDirect (bug #47354)
- fixed default collation bug with session provider table (bug #47332)
- in sessionState provider, timeout value was read from the wrong (root) web.config (bug#47815)
- fixed crash that can occur when oldGuids are used and binary(16) column used for GUID contains a null value (thanks Troy!) (bug#47928)
- fixed indexes schema collection so that it still works with bad table names such as b“a`d (bug #48101)
- fixed guid type so that multi-byte character sets will not effect how it works. A column would be considered a guid if it has a *character* length of 36, not a *byte* length of 36 (bug #47985)
- fixed unsigned types in views when used as entities (bug # 47872)
- now exposing the MySqlDecimal type along with GetMySqlDecimal methods on data reader (bug #48100)
- applied user-suggested patch to enable type-safe cloning (bug #48460)
Thank you for using our product!
MySQL Connector/Net 6.2.1 beta has been released
MySQL Connector/Net 6.2.1, a new version of the all-managed .NET driver
for MySQL has been released. This is a beta release and is intended to
introduce you to the new features and enhancements we are planning. This
release should not be used in a production environment.
It is now available in source and binary form from
[http://dev.mysql.com/downloads/connector/net/6.2.html] and mirror sites
(note that not all mirror sites may be up to date at this point of time
- if you can’t find this version on some mirror, please try again later
or choose another download site.)
The new features or changes in this release are:
- fixed SessionProvider to be compatible with 4.x MySQL, replaced TIMESTAMPDIFF with TIME_TO_SEC (bug#47219)
- implemented support for client SSL certificates
- fixed indexes schema collection so that it still works with bad table names such as b“a`d (bug #48101)
- fixed guid type so that multi-byte character sets will not effect how it works. A column would be considered a guid if it has a *character* length of 36, not a *byte* length of 36 (bug #47985)
- fixed unsigned types in views when used as entities (bug # 47872)
- now exposing the MySqlDecimal type along with GetMySqlDecimal methods on data reader (bug #48100)
- applied user-suggested patch to enable type-safe cloning (bug #48460)
- fixed encrypt keyword that was no longer supported in connection strings. It is obsolete so new code should use the ‘ssl mode’. Encrypt will be removed entirely starting with 6.4 (bug #48290)
- implemented PossibleValues property on MySqlParameter for ENUM and Set types (48586)
What we know may be broken
Documentation is not updated yet.
Please let us know what else we broke and how we can make it better!
MySQL Connector/Net 6.0.5 has been released
MySQL Connector/Net 6.0.5, a new version of the all-managed .NET driver
for MySQL has been released. This is a maintenance release and is approved for use
in all situations.
It is now available in source and binary form from
[http://dev.mysql.com/downloads/connector/net/6.0.html] and mirror sites
(note that not all mirror sites may be up to date at this point of time
- if you can’t find this version on some mirror, please try again later
or choose another download site.)
There are lots of bug fixes in this release so please review the change log.
Thank you!