SMO

SMO if a very powerful library, but if you do not have the correct version installed on your machine (like me) it may make you spend your valuable time looking for non-existing errors. The assembly Microsoft.SqlServer.BatchParser is machine (CPU) specific, which means if you have .NET Framework 64Bit (like I do) installed and trying to run your code with x86 version, it will fail :) Just make sure you have the correct version installed on your system...