Category name:Other

Why Mygeneration Beats the Competition when it comes to codegeneration

April 12, 2005 / Comments Off on Why Mygeneration Beats the Competition when it comes to codegeneration

The main reason why MyGeneration is an excellent tool (Besides support of the dOOdad architecture) is the ability to add several templates to a project. Below is an example of this.

In this project there are four templates needed. Adding a template is very easy. Jus right click on the Rootnode and add a template instance. You can also just execute the selected template so all code within that template is generated.

Then when the template is added you can set the properties for that template.

First you select an output directory, this is where the generated code will be saved. Then you select a database and the tables you need in your project. In this case I needed all tables (that’s why they are blue). Then you save the project. This input is saved as well so you can generate over and over again without any problems. If a table is added, just select that table as wel in the parameters.

Now all that you need is to select the rootnode and hit the green play button on the project explorer. You should get a screen like the one below.

The only thing left to do is add the resulting code to your project and you are done !. I always generate the code directly into my Visual Studio Project directories. So you get a popup from Visual Studio things have changed, hit the OK button and compile.

Now whenever there is a schema change in the database, just implement the change, hit the generate button and be done with those changes.

Using WMI to query the Eventlog

April 8, 2005 / Comments Off on Using WMI to query the Eventlog

After some testing on various ways to query the eventlog I found that a WMI query is the easiest way to query the Eventlog of any (remote) machine. There is very little information about WMI on the internet so I thought it was nice to post this sample snippet. (If you see anything that should be improved please reply on this post)

Public Function QueryLog(ByVal ServerName As String, ByVal LogNames As String, Optional ByVal UserName As String = “”, Optional ByVal PassWord As String = “”) As Collection

‘Set up the new collection
QueryLog = New Collection

‘Set the WMI scope options
Dim oWMI_Scope As New ManagementScope
oWMI_Scope.Path.Server = ServerName
oWMI_Scope.Path.Path = “\” & ServerName & “rootCIMV2”
oWMI_Scope.Path.NamespacePath = “rootCIMV2”

‘ Use the username and passowrd if they are supplied
If UserName = String.Empty And PassWord = String.Empty Then
   oWMI_Scope.Options.Username = UserName
   oWMI_Scope.Options.Password = PassWord
End If

‘ Set impersonation level
oWMI_Scope.Options.Authentication = AuthenticationLevel.Default
oWMI_Scope.Options.Impersonation = ImpersonationLevel.Impersonate
oWMI_Scope.Options.EnablePrivileges =

‘Define the WMI query
Dim oWMI_Query As New ObjectQuery

oWMI_Query.QueryString = “SELECT * FROM Win32_NTLogEvent WHERE ” + GetLogNames(LogNames) + ” AND TimeGenerated > ‘” + LastEventTime + “‘”

‘Create the WMI search engine
Dim oWMI_Results As New ManagementObjectSearcher(oWMI_Scope, oWMI_Query)

‘ Iterate through the resulting collection
Dim oWMI_Object As Object
For Each oWMI_Object In oWMI_Results.Get()
‘ Get the Individual EventLog entries
Dim MyEventClass As New EventLogEntry(oWMI_Object)
‘ Add the Eventlogentry to the collection
‘ Check if the Time of the generated event is greater
‘ then the last time we executed the query if so update that time
If MyEventClass.TimeGenerated > LastEventTime Then
LastEventTime = MyEventClass.TimeGenerated
End If
   ‘Clean up
MyEventClass = Nothing
Next oWMI_Object

‘ Clean up
oWMI_Object = Nothing
oWMI_Scope = Nothing
oWMI_Query = Nothing
oWMI_Results = Nothing

End Function



A very nice EventLog BizTalk Adapter

April 6, 2005 / Comments Off on A very nice EventLog BizTalk Adapter

Hello all you BizTalkers out there….

Just wanted to let you know there is a EventLog Biztalk adapter out there that works very good. It is available on GotDotNet and you can download it by following this link

This is a receive adapter that monitors local or remote Windows event logs and publishes new events, using a provided schema, to the BizTalk environment. This adapter has been used in combination with the Microsoft EMAB to consolidate application events and exceptions with external events that are written to the Windows event Log.

Can’t we kill those very irritating Spammers….


I am getting a lot of replies on my articles lately, unfortunately it is all spam….Running as SQL job removing all spam will not be that hard (maybe it’s running already).

The spam is redirecting us to several gambling sites…

Is there nothing we can do against those sites…. Like flood them with bogus requests so those sites will be so busy they can’t conduct business anymore…….. (Like generate random loginnames and passwords to flood their databases etc.)

A kind of SETI against spammers ! And then not against the people who spam but the people they spam for…



Prevent SQL injection !

In the NorthWind Database the Customer table has a CustomerID field and the field is 5 long.

I am using the MyGeneration dOOdad architecture and I query the database for every customet that has a customerid of ‘ANTON’

In my code this looks like :

Dim cust As New Customers
cust.Where.CustomerID.Value = “ANTON –AND HERE IS SOME STUFF TOO–

So in the code I actually query on : ANTON –AND HERE IS SOME STUFF TOO–

But if I look in the SQL-Profiler I see the following :

exec sp_executesql N’SELECT * FROM [Customers] WHERE [CustomerID] = @CustomerID1 ‘, N’@CustomerID1 nchar(5)’, @CustomerID1 = N’ANTON

So the variable @CustomerID is cutoff at the correct length. This feature could prevent SQL Injection.

The more I look at the dOOdad architecture the more I like it.

Database Documenter MyGeneration Templates

On the MyGeneration WebSite there are  Templates that create database documentation in a very nice (and goodlooking) html format. Tables, Stored Procedures and such are placed in nice html documents.

They’re extremely easy to create and it’s really easy to browse all objects. Can come in pretty handy when you’re doing some coding and want a clean look at your database, or just need the extra documentation for a client or something.

To See what the database reports look like Click here….

dOOdad, Sorting in an ASP datagrid made easy

I have been playing around with the dOOdad architecture and  found out something very nice about this architecture.

Private Sub dgQuestions_SortCommand(Bla bla..) Handles dgQuestions.SortCommand

   ‘ Let’s get the Questions from the cache
   MyQuestions = Cache.Get(“MyQuestions”)

   ‘ Determine some sort orders
   Dim OldSortOrder As String = MyQuestions.Sort
   Dim NewSortOrderD As String = e.SortExpression + ” DESC”
   Dim NewSortOrderA As String = e.SortExpression + ” ASC”

   ‘ See if the sort is on a new column
   If OldSortOrder NewSortOrderA And OldSortOrder NewSortOrderD Then
‘ Sort is on a new column
MyQuestions.Sort = NewSortOrderD
‘ it’s on the same column, reverse the sort
If OldSortOrder = NewSortOrderA Then
MyQuestions.Sort = NewSortOrderD
MyQuestions.Sort = NewSortOrderA
End If
   End If

   ‘Rewind the Questions

   ‘ Remove old instance from cache and add the Sorted one
   Cache.Insert(“MyQuestions”, MyQuestions)

   ‘Bind the Grid

End Sub

The nice part about it is that this piece of code wil look the same for every datagrid. Only the BusinessClass will vary. And presto we have sorting on every column, Ascending and descending !.

MyGeneration Makes life Very easy….

March 16, 2005 / Comments Off on MyGeneration Makes life Very easy….

Well you prabably heard about MyGeneration by now if you are a regular BloggingAbout.Net reader. If you haven’t go and download it now here.

I am currently in the process of rewriting a web application and I am completely doing away with the old DAL. Instead I am using the dOOdad architecture that comes with MyGeneration.

Here are some of the advantages I found so far….

  1. About 40 % less code in the presentation layer ! ( So there is less to review as well )

  2. The code is much more readable.

  3. The Stored Procedures in the database all have a Uniform Name

  4. It’s Faster ! ( probably my old DAL wasn’t as fast as I thought)

  5. 0 lines of code in my DAL. Everything is handled in the generated Classes.

  6. I guess an overall code reduction of 70%

  7. Even the Dynamic SQL is handled in the correct SQL way (optimizing it for successive executes)

  8. Doing away with a lot of Stored procedures that would return a very specific subset

And since it’s a Web application you can do really nice stuff to the sort orders as well. Like the following….

       If Not IsPostBack Then
            Dim PubType As String = Request.QueryString.Item(“PubType”)
            If PubType = Nothing Then
‘ Load Them all
                MyPublications.Where.PublicationType.Value = PubType
                MyPublications.Query.Load() ‘ Load the specific subset
            End If
            ‘ Set Sort order

            MyPublications.Sort = MyPublications.ColumnNames.PublicationDate + ” DESC” 
            ‘ Add to cache
            Cache.Insert(“Publications”, MyPublications)
        End If

Then when you click on a header you can do stuff like….

    Private Sub dgPublications_SortCommand(ByVal source As Object, ByVal e As  System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgPublications.SortCommand
        ‘ Get from the cache
        MyPublications = Cache.Get(“Publications”)
        ‘ Set new sortexpression but keep results sorted on date
        MyPublications.Sort = e.SortExpression + ” , ” + MyPublications.ColumnNames.PublicationDate + ” DESC”
        ‘ Add to cache, but first delete the old one
        Cache.Insert(“Publications”, MyPublications)
    End Sub

You don’t have to requey anything just set the sortcommand on the Entity, rewind the stuff and bind it again….
And you could do the same with filters although I haven’t used that yet….

Also a deletecommand on the datagrid is easy as …..

            Dim key As Integer = CInt(dgPublications.DataKeys(e.Item.ItemIndex).ToString())
            Dim DelPublication As New Publications

Really easy ! No forgotten connetcions or stuff like that. and the code is still easy to read…….

Also note the Difference between the following….
           MyPublications.LoadByPrimaryKey(Key) ‘ Load the specific record
          MyPublications.Where.PublicationType.Value = PubType
     MyPublications.Query.Load() ‘ Load the specific subset
          MyPublications.LoadAll() ‘ Load them all !

This made me do away with a couple of stored procedures……….. Reducing the SQL Code as well…..


Awesome Dynamic SQL generation….


Played around a littlebit with the dOOdad architecture of MyGeneration. Besides a lot of nice features there is also the the dynamic query feature…. Let me show what I mean…..

‘ See if it is in cache
Mymenu = Cache.Get(“DefaultMenu”)
If Mymenu Is Nothing Then
‘get the default Menu
Dim MyMenuID As New MenuID
MyMenuID.Where.MenuDescription.Value = “DefaultMenu”
‘Now get the MenuEntries for the menu !
Mymenu = New MenuData
Mymenu.Where.MenuID.Value = MyMenuID.ID
Mymenu.Where.MenuID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal
‘ Only those rows that we are Authenticated to see
Mymenu.Where.AuthenticationLevel.Value = Session(“AuthenticationLevel”)

   Mymenu.Where.AuthenticationLevel.Operator = MyGeneration.dOOdads.WhereParameter.Operand.LessThanOrEqual
   Mymenu.Query.AddOrderBy(Mymenu.ColumnNames.MenuOrder, ,myGeneration.dOOdads.WhereParameter.Dir.ASC)
‘Cache this menu.
Cache.Insert(“DefaultMenu”, Mymenu)
End If
‘Bind to the grid
MenuGrid.DataSource = Mymenu.DefaultView

In the blue piece of code we set some where parameters and add a sortorder. Everything resulted in the following query beeing executed :

SELECT * FROM [MenuData] WHERE [MenuID] = @MenuID1 AND [AuthenticationLevel] <= @AuthenticationLevel2 ORDER BY [MenuOrder] ASC

And this is a really nice query, nothing wrong with that !. I just was surprised how easy it was !.




  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta