Showing posts with label visual studio 2008. Show all posts
Showing posts with label visual studio 2008. Show all posts

Sunday, November 30, 2008

LINQ with MySQL

LINQ to SQL from Microsoft supports only their SQL Server. How about other popular DBMS such as MySQL ?

I investigate the first result returned from Google using "LINQ with MySQL" query: DbLinq. It's an opensource project which provides "LINQ to SQL" for other databases include MySQL, PostgreSQL, Oracle and SQLite.

However, the project is still at its very beginning stage and I think it will take some time before we can use it in production environment, IMHO.

Here is my setup of DbLinq with MySQL

  • Visual Studio 2008 Professional
  • MySQL 5
  • DbLinq 0.18
  • Windows Vista
1. I first have my database prepared, its name is "Items".

2. Run DbMetal which is a tool comes with DbLinq in "build" folder. I use the following command for my MySQL server. I have user root with no password.

C:\Downloads\DbLinq-0.18\DbLinq-0.18\build>DbMetal /server:127.0.0.1 /database:items /provider:MySQL /user:root /code:Items.cs
DbLinq Database mapping generator 2008 version 0.18.0.0
for Microsoft (R) .NET Framework version 3.5
Distributed under the MIT licence (http://linq.to/db/license)

>>> Reading schema from MySQL database
<<<>


3. You will have a C# code file, Items.cs in my case, automatically generated. This file contains C# classes generated from database schema and the mapping attributes.

4. You may want to compile the project now. I found some errors in my cases:
  • There is no type specified for fields of MySQL's Enum type. You can fix this easily by insert C#'s "string" type. In my case: private _gender; to private string _gender;
  • EntitySet cannot be resolved. Change every occurances to System.Data.Linq.EntitySet instead.

If you can compile your project, you can proceed to the next step.

5. Here is my code for querying from MySQL database. From my setup, it's an ASP.NET web application with a single GridView on the Default.aspx page.



6. Run and see the result : )

Monday, September 29, 2008

Build HTK 3.4 from Source with Visual Studio 2008

I don't know why the HTK website itself did not provide a download for Windows binary release so we don't have to rebuild it again. However, I found that the binary for HTK 3.3 is available for download at their software archive page here (you need to be a registered user first, free of charge.)

I followed the notes posted by Ivan Uemlianin. The notes suggest me to convert the HTK source files which is in Mac format to Windows format. These source files have additional characters (CR CR CR LF) instead of Windows' (CR LF.) So you need to correct them before using Visual Studio's nmake.

Convert Mac's files to Windows'

Ivan Uemlianin himself uses a Python script to convert the files. The method I used here is not involved with programming. But you need a open-source software Notepad++ instead. Download Notepad++ here.

First, I drag all the files those need to be compile into Notepad++. Then, I turn on the "Show all characters in View -> Show all characters.




Next, the most important part, replace all the (CR CR CR LF) with (CR LF.) Fill in the "Find what :" with "\r\r\r\n" and "Replace with" with "\r\n" as shown in the picture below. Notice that the "Extended (..." checkbox at the bottom of dialog is checked. When you are ready, click "Replace all in all opened documents."

It will take a while on an old computer. Mine takes around 40 seconds :(


After the process finished, press the "Save All" button. Now you are ready to nmake the source files! You can follow the readme provided with HTK from now on :)