Category name:Visual Basic

SPX II Has been released.

Ok BizTalkers…..


Maybe you never used it, but version II of the SPX adapter is out. Go and get it here  from gotdotnet. Just to remind you all of the advanages of the SPXII adapter I will sum them up again.



  • Transaction level is adjustable. So if you select none it will be very fast. (impossible in the MS adapter)

  • Caching of parameters is now optional. If you enable caching it will be even faster..(impossible in the MS adapter)

  • Improved receive/send location editing.

  • Possible to use passthru on sends. Makes it really fast..

  • you CAN ppromote properties in the schema’s (impossible in the MS adapter)

Are there any disadvantages then ??? well there are some points to take into account…



  • The SPX II adapter uses only integrated security

  • You can only execute stored procedures

  • The sproc must select something (use FMTONLY ON if there is no data to return )

The SPXII runs in a production environment for months now without any problem. So it’s really realiable.

What the …. CLS Compliancy ( VB Got it right all the time )

Ok, I am not the most experienced programmer around, But this weekend I started with VS2005. I started with converting my old VB.NET project and converted it to VS2005.


No problem whatsoever. everything seemed fine……


But then I hit the F5 Button to run my project. I was a bit disappointed. I got all kind of CLS compliency errors. I never bothered about CLS compliency but now I have to. So I started reading about it……


Then on this hyperlink Ifound the following text…..









Characters and casing
AllCLS-compliant language compilers must follow the rules of Annex 7 of Technical Report 15 of the Unicode Standard 3.0, which governs the set of characters that can start and be included in identifiers. This standard is available at www.unicode.org/unicode/reports/tr15/tr15-18.html.

For two identifiers to be considered distinct, they must differ by more than just their case.


 


Does this mean that VB got it right all the time ?. In VB it was impossible to have two variables that would differ only in ther casing.

Got confused about Strings

I read somewhere on this site the do’s and dont’s about strings…Because I use the + a lot I did run some tests….If you have a construct like this :


Eventlogentry = New Eventlogentry(“There was a failure executing receive location “ +  config.locationname + “. Please review the configuration“)


It doesn’t matter  what you use cause it is only a single instance. You will see only a difference between string.format, string.concat and + if you do a zillion operations.


But remember this is only true if you only instantiate the resultstring. If you are adding to a string within a loop, use the stringbuilder.


Here are some timings :


Concat took        :660.9504
++++++ took        :650.936
Stringbuilder took :1432.0592
String format took :1071.5408


The size of the strings could have imact.  I did one million iterations and the difference between the stuff is minimal. So frankly if you use it only to construct a string to display somewhere… don’t bother use whatevber you like best.


If you”re in a loop use the stringbuilder !


The code I used to produce these timings is in a reply on this post

HashTables are a bunch of nonordered objects reordering themselves to chaos

Ok as a VB programmer I was used to collections instead of Hashtables….Today I used a hashtable cause i thought a hashtable was almost the same as a collection.


I also thought the HashTable was the C# equivalent of a collection, So I started a nice VB project….


ms.Add(“key3”, Nothing)
ms.Add(“key2”,
Nothing
)
ms.Add(“key1”,
Nothing
)
For Each key As String In
ms.Keys
       Debug.WriteLine(key)
Next


This produced :


key1
key3
key2


So the order in the hashtable NOT the order they were added to the hashtable….
I think I stick to the collection…..


Dim ms As New Collection
ms.Add(“key3”, “key3”)
ms.Add(“key2”, “key2”)
ms.Add(“key1”, “key1”)
For x As Integer = 1 To
ms.Count
       Debug.WriteLine(ms(x))
Next


Produces


key3
key2
key1


btw what is the real equivalent of a collection in C#…..come on give a reply and help me on my way…..

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 =
True


‘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
  
QueryLog.Add(MyEventClass.ToXML)
  
‘ 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


 


 

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–
cust.Query.Load()



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
   Else
    
‘ it’s on the same column, reverse the sort
    
If OldSortOrder = NewSortOrderA Then
       
MyQuestions.Sort = NewSortOrderD
    
Else
       
MyQuestions.Sort = NewSortOrderA
    
End If
   End If


   ‘Rewind the Questions
   MyQuestions.Rewind()


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


   ‘Bind the Grid
   BindGrid()


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 !.

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