Using Codesmith and .netTiers

I recently came across Codesmith and .netTiers. It’s one of the best things to happen to me since i started working in VB.NET. You can view the details of what these two are in their sites. Here’s the gist:

Codesmith is an engine for creating code dynamically based on templates. It saves time. .netTiers is a template for Codesmith which creates code for handling SQL Server databases. It creates classes for performing DML (and other operations) on all database tables. This is done by creating collections. You can use it as simply as a collection!

Now, the tutorial I tried to learn from – their official one – is incomplete! Put simply, it doesn’t work. So, I decided to write my own.


  • Download Codesmith trial and .netTiers. Install them!
  • Open Codesmith Explorer from the start menu.
  • Click on Open Folder button in the toolbar and navigate to the Templates folder in the location where you installed .netTiers.
  • Right-click on netTiers.cst file and Execute.

  • Select the database (refer to the screenshot below).
  • Set Entire Database to true.
  • Select Output Directory.
  • Set a namespace name.
  • Generate!

  • If all goes well, you’ll have a new solution in the folder you selected as output directory. Open the solution. You’ll see that it has three projects. All three set to produce DLLs.
  • Now add another project to the solution. This can be a C# or a Vb.NET project. I’m using VB.NET. I’ve named it NorthwindFront.
  • Add a new item to the project. Select Application Configuration File as the type. It’s called App.conf by default. Leave it as it is.
  • Open Enterprise Library Configuration from .netTiers program folder in the start menu.
  • Click on Open File and select the App.Conf you just created.
  • Right-click on Application and click netTiers Block from New submenu.
  • Set these properties. (See screenshot for reference.)
  • .nettiers Application block > data providers > sql data provider instance > DataBase instance: Database instance (select from drop down)
  • .nettiers Application block > cache manager : cache manager (select from drop down)
  • DataAccess application block > connection strings > sql connection string > database > value : [name of database] I used Northwind
  • DataAccess application block > connection strings > sql connection string > server > value : [name of sql server machine] I used (local)
  • Save the file. If there’s an error, restart. If it still doesn’t work, post a comment and tell me what it says!

  • This generates some *.conf files in your project directory. Go there and copy all of the *.conf files to your bin directory.
  • That concludes the netTiers part of the tutorial. That’s all you need to do to set netTiers up. Now, you need to see how to use it.

Here’s a project I created while learning to put this netTiers to use. It’s pretty basic but does all three DML operations. To run it, you need to have SQL server running on (local) with the default Northwind database using Integrated Security for login. To change these settings, see the last section of this tutorial.

Download Project.

Run this project and try these tasks:

View the list of Employees. Try typing a name in the text box to see dynamic searching in action. You can also use up, down, page-up and page-down keys in the textbox for navigation.

Enter new employees. (Just enter the values and click on Add.)

Modify past records. This is the most functional part. You can enter an ID in the ID field and hit enter to load that record in the boxes below. If that ID doesn’t exist, you’re shown the view box in which you can select an employee and hit enter to load that.
Changing SQL server database and server

If you want to change these settings, open up the DataConfiguration.conf file from your bin folder and edit the settings. (See screenshot.)

If you download the project and try running it, you’ll notice that it doesn’t work! This is because of the way references are created by netTiers. Here’s what you need to do to fix it. I know this isn’t the right solution. I’m trying to get to do this properly. If you find something, do leave me a note.

  • Open the solution. Open the Properties of the Northwind.DataAccessLayer project.
  • In the References Path section of Common Properties, change the path to [$YourSolutionPath]/References.
  • Do the same for Northwind.DataAccessLayer.SqlClient project.
  • Compile/run the project.

If you find something wrong and/or missing in this tutorial, please let me know.

28 thoughts on “Using Codesmith and .netTiers

  1. NetTiers template really saves lots of effort and time. But is there any version of NetTiers available that generate VB.NET code?

  2. Code generated for C# goes into a dll. So, it doesn’t matter if it’s C#. That’s the beauty of .net. The sample project shows this. I’ve used the C# project for my own sample!

  3. Open the solution created. It would have 3 or 4 projects already there. They’d be of C#. Just create another project (VB.Net) and add the other projects to its references.

    (Download the sample project for details!)

  4. Hi

    I really liked your tutorial. It certainly covers a lot of gaps in the netTiers doc.

    I downloaded the example project. However it seems that the file is damaged. Could you send me a copy.



  5. By damaged, do you mean that the rar is corrupt or that the project doesn’t compile. If you mean the second, read through the final part of the tutorial. You have to make some changes before it’ll run.

    If it’s the first reason, I’ll upload the rar again. Tell me which one it is.

  6. I think the .rar is corrupted. winrar displays the followin message for all files in the rar

    ! C:\NetTiers\NetTiersTest.rar: Unknown method in NetTiersTest\NorthWind.sln
    ! C:\NetTiers\NetTiersTest.rar: Unknown method in NetTiersTest\

    I tried to download it again from
    [snip…]but I’m getting this

    The site you have requested could not be found. (404)

    Could you send the file by email.



  7. The rar is not corrupt as long as you can download and extract it. (The file is offline for a while because i’m changing file servers).

    Just take a look at the code to see how to use it. Then follow the tutorial to create your own. Just take it one step at a time and you’ll get it.

    Or, what you can do is, just try to do the steps listed in the tutorial. After that, you’ll be able to understand how to use it. You don’t really need the rar file.

  8. I’m trying to download your sample project but I’m getting a 404 error? Love to take a look at this.


  9. Thanks for this tutorial. Unfortunately, I can’t figure out how to hook netTiers applications block into Enterprise Library configuration. To be more precise, every time I open a new Application configuration within Enterprise Library configuration, I got for instance
    1. Caching Application Block
    2. Configuration Sources

    8. Security Application Block
    but no netTiers Application Block as mentioned in the tutorial.

    Thanks for your reply.

  10. You must not have netTiers properly installed. I really have no idea but I think you may have a version conflict. Try re-installing Codesmith and netTiers.

    Or, you can just copy/paste the xml code from the sample project into your App.conf file. Not sure that’d work though.

  11. I recall there is no particular installation for netTiers (just to unzip the downloaded file into a directory). could you please be precise when you said: Open Enterprise Library Configuration from .netTiers program folder in the start menu.
    Thanks for your reply.

  12. I have the same problem 😦 I don’t know how to get netTiers config into Enterprise Library Configuration.

    Thanks in advance.

  13. The way to handle codesmith and netTiers is to generate code from them and use the generated project in another separately created project of your own. This way, the new project can be in ASP.Net, VB.Net or any other language and can use any technology you want.

  14. Net Tiers is just extracted to a directory, there is no *installation* as such and therefore nothing gets put into the start menu – you have used enterprise manager in the tutorial – and your instructions say to launch it from the nettiers folder in the start menu. This is where i become lost.. So therefore i downloaded enterprise manager – and also in the nettiers program files directory you can launch enterprise manager. But they do not appear with the nettiers application block in and i cant seem to follow along with this as your screenshots suggest. Can you offer any advice on this i would really appreciate it. Thanks

  15. Yeah same here, I’m have the same problem as ‘darrell’ above.

    “Now, the tutorial I tried to learn from – their official one – is incomplete! Put simply, it doesn’t work. So, I decided to write my own.”

    Yours is incomplete as well 😦

  16. Hi,

    I really like your tutorial. I am new to CodeSmith. The latest NETTiers does not work well for Windows-Based application.

    Please help me by downloading CodeSmith & Nettiers & see
    if your code still work.

    Thank you very much for your time & help.

  17. I had only previously seen one web page when I googled into your site – I did not understand how substantial it’s! Brilliantly completed! I hope you have earned awards for it, they are deserved.

Comments are closed.