.NET mySql PerformanceMonitor Class

The 6.x mySql Connector for .NET comes with two performance counters that seem to be working rather well. If I call the same stored procedure 1,000 times… the metadata is only retrieved from the server the first time. All subsequent calls utilize the client-side cache. You can see this using the Performance Monitor graph in Control Panel -> Administrative Tools -> Performance.

Also, you have set the following parameter in your connection string:

Use Performance Monitor=true;

HardProcedureQueries – The number of times a procedures metadata had to be queried from the server.

SoftProcedureQueries – The number of times a procedures metadata was retrieved from the client-side cache.

Posted in .net, mysql | Leave a comment

Concrete Example – Mocking .NET Objects w/NUnit

Geoff Lane does a very good job of explaining .NET Mock objects.

People were requesting a “concrete” example so I implemented an example C# console application (although this can easily be made into an ASP.NET web application).

Geoff hints to using Spring .NET to wire things up, but that might be too confusing for some people. And maybe a little over board for a simple example (open closed principle).

So instead I created a PersonServiceManager that creates a “concrete” PersonService via IPersonRepository injection. The GUI communicates to the PersonServiceManager through an IPersonService interface.

Instead of “mocking” an IPersonRepository, we are actually implementing it then injecting it into PersonService (just like our NUnit test). The PersonServiceManager handles passing the appropriate database connection string down to the data layer. In my example, the data layer object PersonDb (which implements IPersonRepository and used for injection) utilizes the DbProviderFactory.

Here is the sample source (C# Console App).

Also remember that the sample source could be broken down into separate assemblies in a real world project.

Posted in .net, testing | 3 Comments

Side by Side – IE8, IE6, IE5.5, IE5, IE4.01, & IE3

Running IE8 on your computer? The included developer tools are great. Need to switch to IE7 mode? No problem using IE8.

But what about IE6, IE5.5, IE5, IE4.01, and IE3? Here is a free multiple installer you can use. And it works! And I performed a virus scan (before and after the install)… no problems detected.

Unfortunately, a couple of my JQuery sites look weird with IE6. I know I know, its not JQuery… rather its the IE6 CSS quirks (among other things… standards compliance… cough… cough…).

http://tredosoft.com/Multiple_IE

Posted in css, ie, jquery, testing | Leave a comment

Example mySql IsDate Function

Here is an example mySql IsDate function using a regular expression:

CREATE DEFINER=`root`@`localhost` FUNCTION `IsDate`(var varchar(25)) RETURNS tinyint(4)
DETERMINISTIC
BEGIN
/* 05/17/2009, 5/01/2009, 5/1/2009 */

declare result tinyint;

select trim(var)

REGEXP '^([1-9]|0[1-9]|1[012])/([1-9]|0[1-9]|[12][0-9]|3[01])/(19|20)[0-9][0-9]'

into @result;

return @result;
END
Posted in mysql | Leave a comment

MySql Connector .NET MySqlBulkLoader Example

Here is a MySqlBulkLoader example I quickly wrote to import 65,000 records into a mySql 5.1 database using the mySql Connector 5.2.5. And yes, its fast as snot (the lead programmer at my first programming job out of college invented the term).

.NET Reflector helped me figure out the follow details:

– the default FieldTerminator is “\t”
– the default LineTerminator is “\n”
– the default FieldQuotationCharacter is ”
– the .Load() method both opens and closes the connection

Also, the mySql documentation obviously helped to explain a lot including the “\r\n” Win32 line terminator in my example (I used Excel to export the CSV). The database user in this example needs “insert” permission.

Download the VB.NET, Sql, and CSV files here.

Posted in .net, mysql | 8 Comments

Unit Testing ASP.NET App_Code

I learn something new every day. Today, its the ability to Unit Test code in the App_Code folder using Visual Studio 2008 Professional.

Most of the ASP.NET projects that I work on have their business logic contained in a separate assembly. However, a recent smaller project has some business classes residing in the App_Code directory.

Tip: Just make sure you watch your dynamic port assignments.

Posted in .net, visual studio | Leave a comment

Disable the Shutdown Event Manager in Windows Server

Want to get rid of this screen (Shutdown Event Manager) in Windows Server 2003 and Windows Server 2008?

Shutdown Event Manager

Do this:

Start -> Run -> gpedit.msc

Computer Configuration -> Administrative Templates -> System

Disable “Display Shutdown Event Tracker”

Posted in windows server | Leave a comment

Using Microsoft ADO.NET Entity Framework with MySQL

Unfortunately, this week’s Using Microsoft ADO.NET Entity Framework with MySQL Webinar is being postponed to Tuesday November 4, 2008. Myself and many others are looking forward to some (if not all) entity framework support. It seems that I check the mySQL dev forum daily for updates.

The myDirect.NET product offers support for the ADO.NET Entity Framework with a commercial license fee.

Posted in .net, mysql | 2 Comments

Visual Studio 2008 Justification

There are two primary justifications for my company’s latest purchase of Visual Studio 2008 Professional –

1. The ability to “target” previous .NET versions.
2. The integrated unit testing.

While we still have not setup the automatic builds (command line)… and we still utilize NAnt… the integrated unit testing feature of Visual Studio 2008 rocks. Sure there are alternatives (we still have some projects with NUnit testing)… and various mocking frameworks, however the ability to “right click” create unit test/private accessor is very productive for us.

Posted in .net, testing | Leave a comment

VB.NET InternalsVisibleTo

Unfortunately, the InternalsVisibleTo attribute does not work with the .NET 2.0 Framework for VB.NET. However, I just installed Visual Web Developer 2008 Express SP1 Beta and it works! Thanks Microsoft for making my NUnit testing a little easier (and cleaner).

To reproduce:

Create a VB.NET class library named ClassLibrary1. Add a single class with only a friend constructor. Add the following attribute to AssemblyInfo.vb:

Assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ClassLibrary2")

Add another VB.NET class library named ClassLibrary2. Add a project reference to ClassLibrary1. Verify that you are able to construct an instance of the above class.

Posted in .net, testing | Leave a comment