Wednesday Jan 25, 2012

MySQL Connector/Net 6.5.1 beta has been released

MySQL Connector/Net 6.5.1, a new version of the all-managed .NET driver for MySQL has been released.  This is a beta release of our newest connector and comes with several new features.  It is of beta quality and should not be used in any production environment.  It is appropriate for use with MySQL server versions 5.0-5.6

It is now available in source and binary form from http://dev.mysql.com/downloads/connector/net/#downloads and mirror sites (note that not all mirror sites may be up to date at this point-if you can't find this version on some mirror, please try again later or choose another download site.)

This new versions brings new features such as
  • Exception and command injector support
  • Millseconds support
  • Better partial-trust support
  • Better intellisense including auto-completion when editing stored procedures or .mysql files
These features are not yet documented in the shipping documentation.  We have posted a series of posts to our blog outlining these new features.

You can leave comments here on the blog post or post questions on our forums at http://forums.mysql.com/

Enjoy and thanks for the support!      

Tuesday Jan 03, 2012

Running Connector/Net 6.5 inside Medium-Trust Level

Connector/Net is now enabled to work inside a Medium/Partial Trust security level. Just download the new 6.5 version to use with your .Net application and you should be able to see it working just fine.[Read More]

Using MySqlClientPermission Class on Connector/Net 6.5 to restrict data access

The release of the new 6.5 Connector/Net version includes a MySqlClientPermission class to help all the users define the security polices to use in the database connections within any application using a MySQL database.[Read More]

Intellisense Support

One of the cool features coming in Connector/NET 6.5 is the support in Visual Studio 2010 of Intellisense for MySql files.

As you probably know, the capability of editing mysql files (in the way of both .mysql raw files included in the solution and stored procedures/functions from Server Explorer) has been around for a while, yet a missing piece of the puzzle was to have advanced completion of sql statements in those files… until now.

[Read More]

Milliseconds value support on DateTime Columns

Since the release of the 5.6 Community MySQL Server there is support for the milliseconds value in Time, TimeStamp and DateTime types.  You can find more information on this new feature at (http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html).  Starting with version 6.5, Connector/Net fully supports milliseconds. This support does not affect compatibility with older versions of MySQL and it gives you the ability to use fractional seconds when combining Connector/Net 6.5 with MySQL Server 5.6 or later.  Let's see how we should use it.

Creating a DateTime column that include Milliseconds value.

You can do this either using Connector/Net or using any MySQL client with a valid connection to your database.

For this case we're going to use MySqlCommand class within a console application in VS 2010.

1. Define the connection string to use and create the table in our database: 

MySqlConnection conn = new MySqlConnection("host=localhost;User Id=root;pooling=False;Persist Security Info=True;Connection Reset=True;Allow User Variables=True;database=test;"); 

MySqlCommand cmd = new MySqlCommand();

cmd.Connection = conn;

cmd.CommandText = "CREATE TABLE Test (id INT NOT NULL, dt DATETIME(6), PRIMARY KEY(id))";

cmd.ExecuteNonQuery();

2. Now let's use a MySqlParameter to insert one row that has our field dt with milliseconds value:

cmd.CommandText = "INSERT INTO Test VALUES(@id, @dt)";

cmd.Parameters.Add(new MySqlParameter("@id", 1));

MySqlParameter dt  = new MySqlParameter();

dt.ParameterName = "@dt";

dt.MySqlDbType = MySqlDbType.DateTime;

dt.Value = "2011-01-01 12:34:59.123456";

cmd.Parameters.Add(dt);

cmd.ExecuteNonQuery();

3.  Query your table to see that this value was in fact saved including the milliseconds value:

cmd.CommandText = "SELECT dt FROM Test WHERE id = 1";

cmd.Parameters.Clear();

cmd.Connection = c;

cmd.Prepare();

MySqlDataReader rdr = cmd.ExecuteReader();

while (rdr.Read()){

Console.WriteLine(rdr[0] + " --- " + rdr.GetMySqlDateTime(1).Millisecond + " -- ");

}

rdr.Close();

conn.Close(); 

The output for this code should be:

 1 --- 123456 --

Notice that I used the GetMySqlDateTime method to read the complete value of the milliseconds. If you use GetDateTime method instead you will have only the first three digits since this is a limitation on the milliseconds value for the DateTime class on the .Net framework. You can also use this feature using prepared statements.

Please feel free to ask any questions and post any comments you have.  We would like to hear you!

Happy MySql/Net Codding!! 

About

Here's where you'll hear about all the new and fun stuff we are doing with MySQL on Windows.

Search

Categories
Archives
« January 2012 »
SunMonTueWedThuFriSat
1
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
26
27
28
29
30
31
    
       
Today