That looks just like Jeff Procises code I translated into VB. So that is not a help.
Here is the provider I translated from that code in C# to VB. This is how it currently stands, I have a few items broken out trying to figure out why only the first node is getting passed to the menu controls referencing the data. BTW, I have a page with a bread crumb, Menu and Treeview trying to figure this one out. If I add a node with the first node as the parent, it shows up as a sub menu. But I do not want that in this case, I reall need say the top 5 pages listed horizontally in the menu, then I will drop the sub-menus in. Another thing, I added a few more fields to the sitemap database table, and I do not reference values in a datareader by the Index, I reference them by name. This way I know I get the field I want.
Imports System.Web.Caching
Imports System.Data.Common
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Imports System.Security.Permissions
Imports System.Collections
Imports System
Imports System.Collections.Generic
Imports System.Web.Configuration
Imports System.Configuration.Provider
<SqlClientPermission(SecurityAction.Demand, Unrestricted:=True)> _
Public Class SqlSiteMapProvider
Inherits StaticSiteMapProvider
'
Private _errmsg1 As String = "Missing node ID"
Private _errmsg2 As String = "Duplicate node ID"
Private _errmsg3 As String = "Missing parent ID"
Private _errmsg4 As String = "Invalid parent ID"
Private _errmsg5 As String = "Empty or missing connectionStringName"
Private _errmsg6 As String = "Missing connection string"
Private _errmsg7 As String = "Empty connection string"
Private _errmsg8 As String = "Invalid sqlCacheDependency"
Private _cacheDependencyName As String = "__SiteMapCacheDependency"
Private _connect As String
Private _database, _table As String
Private _2005dependency As Boolean = False
Private _nodes As New Dictionary(Of Integer, SiteMapNode)(16)
Private _root As SiteMapNode
Private _lock As New Object()
Public Overrides Sub Initialize(ByVal name As String, ByVal config As NameValueCollection)
' Verify parameters
If config Is Nothing Then
Throw New ArgumentNullException("config")
End If
If [String].IsNullOrEmpty(name) Then
name = "SqlSiteMapProvider"
End If
' Add a default "description" attribute to config if the
' attribute doesn't exist or is empty
If String.IsNullOrEmpty(config("description")) Then
config.Remove("description")
config.Add("description", "SQL site map provider")
End If
' Call the base class's Initialize method
MyBase.Initialize(name, config)
' Initialize _connect
Dim connect As String = config("connectionStringName")
If [String].IsNullOrEmpty(connect) Then
Throw New ProviderException("Could Not Initialize Connection String.")
End If
config.Remove("connectionStringName")
If WebConfigurationManager.ConnectionStrings(connect) Is Nothing Then
Throw New ProviderException("Problem with Web Configuration Manager Connection Strings are Null or Empty.")
End If
_connect = WebConfigurationManager.ConnectionStrings(connect).ConnectionString
If [String].IsNullOrEmpty(_connect) Then
Throw New ProviderException("Problem with Connection String Null or Emtpy.")
End If
' Initialize SQL cache dependency info
Dim dependency As String = config("sqlCacheDependency")
If Not [String].IsNullOrEmpty(dependency) Then
If [String].Equals(dependency, "CommandNotification", StringComparison.InvariantCultureIgnoreCase) Then
SqlDependency.Start(_connect)
_2005dependency = True
Else
' If not "CommandNotification", then extract
' database and table names
Dim info As String() = dependency.Split(New Char() {":"c})
If info.Length <> 2 Then
Throw New ProviderException("No Dependancy Set.")
End If
_database = info(0)
_table = info(1)
End If
config.Remove("sqlCacheDependency")
End If
' Throw an exception if unrecognized attributes remain
If config.Count > 0 Then
Dim attr As String = config.GetKey(0)
If Not [String].IsNullOrEmpty(attr) Then
Throw New ProviderException("Unrecognized attribute: " + attr)
End If
End If
End Sub 'Initialize
Public Overrides Function BuildSiteMap() As SiteMapNode
SyncLock _lock
' Return immediately if this method has been called before
If Not (_root Is Nothing) Then
Return _root
End If
' Query the database for site map nodes
Dim connection As New SqlConnection(_connect)
Try
Dim command As New SqlCommand("proc_GetSiteMap", connection)
command.CommandType = CommandType.StoredProcedure
' Create a SQL cache dependency if requested
Dim dependency As SqlCacheDependency = Nothing
If _2005dependency Then
dependency = New SqlCacheDependency(command)
Else
If Not [String].IsNullOrEmpty(_database) And Not [String].IsNullOrEmpty(_table) Then
dependency = New SqlCacheDependency(_database, _table)
End If
End If
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
If reader.Read() Then
' Create the root SiteMapNode and add it to site map
_root = CreateSiteMapNodeFromDataReader(reader)
AddNode(_root, Nothing)
AddNode(New SiteMapNode(Me, "Test1", "textTools.aspx"), Nothing)
AddNode(New SiteMapNode(Me, "Test2", "textMonitoring.aspx"), Nothing)
' Build a tree of SiteMapNodes under the root node
While reader.Read()
' Create another site map node and add it
AddNode(CreateSiteMapNodeFromDataReader(reader), Nothing)
' AddNode(CreateSiteMapNodeFromDataReader(reader), _
' GetParentNodeFromDataReader(reader))
End While
' Use the SQL cache dependency
If Not (dependency Is Nothing) Then
HttpRuntime.Cache.Insert(_cacheDependencyName, New Object(), _
dependency, Cache.NoAbsoluteExpiration, _
Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, _
New CacheItemRemovedCallback(AddressOf OnSiteMapChanged))
End If
End If