TDD developer

October 28, 2009

Sql Azure first contact

Filed under: .NET — makka @ 10:06 pm
Tags: , , ,

Tonight I’m starting a new project. Porting to the cloud a real application running “on premises”.

The first step of this migration is the database. For the moment I want just to recreate the database schema. The data migration will be done in the future but since I hope the database schema will be the same I believe this step will be an easy task.

I have already setup my SqlAzure credential (there are many posts about it). If you want to connect using SSMS (SQL Server Managment Studio) this are the step you need to follow:

  1. Cancel the first connection dialog that pops up when you open SSMS.
  2. Click on the New Query button from the toolbar
  3. Enter your server name: eg. xxxyyyzzz.database.windows.net
  4. Enter your Login: username@xxxyyyzzz
  5. Hit connect.

This is my login prompt:

image

If you get this error: “Invalid object name ’sys.configurations’” it’s because you didn’t cancel the first logon prompt.

Once you logged on you are ready to go. In my case I have 2 scripts: one for database creation and one for the creation of the database’s objects (tables & indexes).

image

The first it’s very very simple. Just the common CREATE DATABASE statement in order to create the db. No problem with that.

image

Now my database is up & running. I need a new connection to run the second script. It this connection I must set the database name in the options as shown below:

image

Unfortunately with the second I get some errors at the first run cause I’m using some SqlServer features that are not available on SqlAzure. Using the “Parse” button several times I can detect which features are not supported and than correct my script.

image

At the end my script pass and my database is ready to use.

In the next post I’ll try to migrate the web application (which is built with ASP.NET MVC V1)

July 26, 2009

IronRuby

Filed under: .NET — makka @ 12:35 pm
Tags: ,

Today I watched this realy interesting presentation about IronRuby. Now that the implementation is near the version 0.9 I believe it’s time to start using IronRuby in a production environment. First of all I’ll use it for testing (RSpec) and for developing web application (Rails and IronRubyMVC)

If you have time don’t miss it!

Iron Ruby (Ben Hall) from Vista Squad on Vimeo.

June 28, 2009

Google Web Toolkit (GWT) on Ubuntu Desktop 9.04

Filed under: Uncategorized — makka @ 12:20 pm

After watching a Google Wave video presentation my interest in the Google Web Toolkit (GWT) grown so I decided to create Virtual Machine with all the stuff I need to play with GWT. I’m using a VMWare virtual machine with Ubuntu Desktop 9.04.

Im order to setup the development environment I found this great blog post with detailed informations on how to set up Glassfish, Eclipse, Google Web toolkit (GWT), Development Environment on Ubuntu Desktop 9.04.

I follow the instruction step by step. I’m not a Linux geek but everything was quite easy. Here below you can see my first application build with GWT.

Capture

Technorati Tag: ,,

June 25, 2009

Moonlight on Ubuntu 9 with Firefox

Filed under: Uncategorized — makka @ 7:14 pm

Just few mouse clicks and it works like a charm.

Here below you can see the site of the italian national television build with silverlight 2.0

Capture

Technorati Tag: ,,

June 21, 2009

NHibernate 2.1.0 beta 2

Filed under: .NET, nhibernate — makka @ 5:15 pm
Tags: ,

Today NHibernate team released version 2.1.0 beta 2

This version contains a fix for bug that cause some problem with MS Sql server execution plans (more details here).

Be carefull if you use an HQL query cause the actual parser is not still able to use the correct parameter type. I hope also this issue will be solved in the future versions but in the meantime you can use the solution I wrote in post linked above.

Technorati Tag: ,

April 19, 2009

LINQ to NHibernate

Filed under: .NET, nhibernate — makka @ 2:29 pm
Tags: , ,

This is a very great news for NHibernate!

Time for another update; it’s been a while since the last one. Good progress has been made on the new HQL AST Parser port from Hibernate, and it’s now in a state where it’s usable, passing the vast majority of the tests within the NHibernate test suite. Of those that are failing (around 8 out of over 1600), we are currently discussing on the developers group whether we will live with these minor breaking changes, or do continued work on the parser to get everything passing.

March 10, 2009

NHibernate queries & sql server execution plans

Filed under: .NET, nhibernate — makka @ 8:57 pm
Tags: , , ,

In these days I’m working with Andrea on a web application using ASP.NET & SQL Server . You should kwon that Andrea, is a SQL Server MVP, but fortunately is not a T-SQL taliban so he agree without hesitation when I proposed to use NHibernate to build our data access layer. When a tool can help us while building an application why not use it ?

As you can image a skilled DBA like Andrea can rapidly find a bottleneck in any query fired to a database. While writing a simple query using NHibernate API we noticed a strange behavior of NHibernate 2.0 with parameters. Here is the code we wrote:

using (ISession session = factory.OpenSession())
{
	//nvarchar(4)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetString("desc", "zon%")
		.List();

	//nvarchar(5)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetString("desc", "zone%")
		.List();
}

This code generates these two sql queries:


exec sp_executesql N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',N'@p0 nvarchar(4)',@p0=N'zon%'

exec sp_executesql N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',N'@p0 nvarchar(5)',@p0=N'zone%'

As you can see the parameter type is different in the two statements. This unfortunately cause SqlServer to generate two different exection plans. If you need the best performace you should avoid this behaviour. If you send to the database queries using the same parameter (type & size) SqlServer use his internal cache. You have already pay for it so why not to use it ?

I had the pleasure to discuss with Fabio Maulo about this topic (you can read here. The conversation is in italian). At the end I found this solution:

I edited my hibernate.cfg.xml file adding this node to the xml

<property name="prepare_sql">true</property>

and then I wrote this code:

using (ISession session = factory.OpenSession())
{

	//nvarchar(10)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "zoneh%", TypeFactory.GetStringType(10))
		.List();

	//nvarchar(10)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "neh%", TypeFactory.GetStringType(10))
		.List();
}

Now with this code NHibernate generates these two sql queries:

declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@p0 nvarchar(10)',N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',@p0=N'zoneh%'
select @p1

declare @p1 int
set @p1=2
exec sp_prepexec @p1 output,N'@p0 nvarchar(10)',N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',@p0=N'neh%'
select @p1

This is better cause the parameters length is always the same. Now your database will thank you for this! But wait you can still do something better.

If your database column type is a varchar and not nvarchar you can improve your code using a different SqlDbType. How ? Whit his code:

using (ISession session = factory.OpenSession())
{
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "z%", TypeFactory.GetAnsiStringType(15))
		.List();

	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "za%", TypeFactory.GetAnsiStringType(15))
		.List();
}

Now the parameter type is a varchar and the size is always 15. Whit this latest improvement you remove a CONVER_IMPLICIT operation from your query execution plan (futher details here but in italian ). This cast operation cost something so if you don’t need it why to remove it ?

I hope this will help someone (dev & dba) in the future!

February 1, 2009

NAnt sucks and Rake rocks

Filed under: continuous integration — makka @ 1:34 pm
Tags: , , ,

In these days I’m moving my build scripts from NAnt to Rake. The main reason for doing this is that I’m moving from external dsl to an internal dsl. Internal DSLs are often the most approachable form of DSLs to write. Unlike external DSLs you don’t need to learn about grammars and language parsing, unlike language workbenches you don’t need any special tools. With internal DSLs you work in your regular language environment.

This means that now I build my build scritps just with ruby. I believe this is a good way to learn this nice language. Rake in fact is nothing more that a Ruby library.

Getting started with Rake and .NET is very easy:

  • Download the Ruby for windows one click installer.
  • Install it
  • Create a file Rakefile.rb (type is text file)
  • Type:
    task :default => :build
    
    task :build => [:compile, :test, :deploy] 
    
    task :compile do
      params = '/t:Rebuild /nologo /v:m /p:Configuration=Release src\demo.sln'
      msbuid = 'C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe'
      sh "#{msbuid} #{params}"
    end
    
    task :test do
     runner = 'tools\\Gallio\\Gallio.Echo.exe'
     assemblies = FileList["src/**/bin/Release/*.Fixture.exe"]
     extension = '' #'/e:TeamCityExtension,Gallio.TeamCityIntegration'
     sh "#{runner} #{assemblies} #{extension}"
    end
    
    task :deploy do
        sh "echo Task not yet implemented!"
    end
  • Open a command prompt (Start->Run->Cmd)

  • Type: cd c:\[my RakeFile.rb folder] (obviously put your own path in)

  • Type: rake
  • Done!

As you can see here above with rake there is no need to learn some crazy xml syntax. Whit this little script I compile my solution and run all unit tests. No need to write xml, only some ruby code.

Nothing more nothing less.

Technorati Tag: ,,,

January 6, 2009

PowerCommands for Visual Studio 2008

Filed under: .NET — makka @ 1:18 pm
Tags: ,

I think Visual Studio 2008 is a great development environment but you can still improve its usability with some free add-in. For example "PowerCommands for Visual Studio 2008" is a set of useful extensions for VS 2008 that add a bunch of cool features to the IDE.

You can download the installer from here

Technorati Tag: ,

January 5, 2009

NAnt + NDepend.Console.exe and relative paths

Filed under: continuous integration — makka @ 1:31 pm
Tags: , ,

If you read the documentation of NDepend.Console.exe you learn that relative paths are not supported. These remarks also apply to paths provided with options /InDirs /OutDir and /XslForReport.

Here you can see the result of a wrong line command

image

and here the result of a right line command

image

Unfortunately this is a problem for my solutions cause I need always relative path. My solution are continuous integrated using TeamCity and in my setup the build agent checks out sources in a random folder on the build agent machine (for eg. C:\BuildAgent\work\12724a65ddd4c6d0).

Here the Version Control Settings page of my project inside my TeamCity server where you can set the checkout directory.

image

Using relative path for me is a plus cause allow developers to freely decise the checkout project folder. For some of our customer this has been a project requirement.

Ok now you know why I need relative paths. Now I want to explain how I use NAnt + NDepend inside my continuous integrated solution. 

This is the target I use to run NDepend.Console.exe.

image

As you can see using the directory::get-current-directory I can build an absolute path at run-time. Maybe this result can be obtained using the built-in property  ${nant.project.basedir} but this is marked as deprecated so I prefer to use the directory::get-current-directory function.

Next Page »

Blog at WordPress.com.