Sacha Tomey

Sacha Tomey's Blog

LoadControl Changes in .NET 2.0

In .Net 1.x you can dynamically load user controls using the Page.LoadControl member.  Providing you namespace your classes the same or qualify the classes correctly you can cast the return value of LoadControl to an object of your user control type.
MyUserControl myUserControl = (MyUserControl )LoadControl("MyUserControl.ascx");
MyFolderedUserControl myFolderedUserControl = (MyFolderedUserControl )LoadControl("Folder/MyUserControl.ascx");
Moving to .Net 2.0, where namespaces are no longer a key reference mechanism, an additional step is required.
In the partial code behind class, specify the loading and casting as you would in Net 1.x.
MyUserControl myUserControl = (MyUserControl)LoadControl("MyUserControl.ascx");
MyFolderedUserControl myFolderedUserControl = (MyFolderedUserControl)LoadControl("Folder/MyUserControl.ascx");
However, when you attempt to compile this code, the second line will fail, this is because the foldered user control is not part of the main assembly and the compiler knows nothing about it.  To fix this you need to add a reference attribute to the aspx file that will host the user control:
<%@ Reference Control="Folder/MyUserControl.ascx" %>

Invalidating ASP.NET OutputCache

You can invalidate ASP.NET output level cache using cache dependencies.
The ASP.NET webform should contain something like this:
<%@ OutputCache Duration="60" Location="Server" VaryByParam="None" %>
If you need to invalidate the cache prior to the 60 seconds elapsing you can do this by setting up a cache dependency between the page and an item in the cache:



Now, when the "MyCachedData" cachekey is changed or invalidated the cached page is invalidated too.

Scripting SQL Server 2000 Jobs

SQL Server Agent Jobs can be scripted with the following SQL DMO VB Script:
Dim conServer
Dim fso
Dim iFile
Dim oJB
Dim strJob
Dim strFilename
Const ioModeAppend = 8
Set conServer = CreateObject("SQLDMO.SQLServer")
conServer.LoginSecure = True
conServer.Connect "SQL2K_Server"

strFilename = "c:\SQLJobs.sql"

For Each oJB In conServer.JobServer.Jobs
    strJob = strJob & "--------------------------------------------------" & vbCrLf
    strJob = strJob & "-- SCRIPTING JOB: " & oJB.Name & vbCrLf
    strJob = strJob & "--------------------------------------------------" & vbCrLf
    strJob = strJob & oJB.Script() & vbCrLf
Set conServer = Nothing

Set fso = CreateObject("Scripting.FileSystemObject")
Set iFile = fso.CreateTextFile(strFilename, True)
iFile.Write (strJob)
Set fso = Nothing


Enterprise Library Woes

When deploying the enterprise library to a production server the following errors (or similar) can be fixed by running the 'InstallUtil' utility against the enterprise library assemblies.

Failed to fire the WMI event 'DataConnectionOpenedEvent'. Exception: System.Exception: This schema for this assembly has not been registered with WMI.

at System.Management.Instrumentation.Instrumentation.Initialize(Assembly assembly)

at System.Management.Instrumentation.Instrumentation.GetInstrumentedAssembly(Assembly assembly)

at System.Management.Instrumentation.Instrumentation.GetFireFunction(Type type)

at System.Management.Instrumentation.BaseEvent.get_FireFunction()

at System.Management.Instrumentation.BaseEvent.Fire()

at Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.InstrumentedEvent.FireWmiEventCore(BaseEvent baseEvent).

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In leo. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam a elit id turpis semper auctor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse bibendum luctus est. Duis pharetra mauris sed mauris. Aenean lacinia lectus iaculis ante. Vivamus pharetra ipsum sit amet nisi dapibus lacinia. Aliquam feugiat hendrerit lorem. Morbi vestibulum euismod augue. Proin tempor condimentum sem. Nulla facilisi. Proin vestibulum. Pellentesque tellus nisl, dignissim id, congue nec, egestas a, leo. Vivamus eget nunc sed nisi pretium nonummy. Vivamus dapibus lectus in eros.

Aliquam vulputate cursus libero. Vestibulum dictum, dui ut porta adipiscing, sem massa fringilla libero, at sagittis lorem sapien vel nisi. Nulla sit amet arcu sed dolor luctus placerat. Phasellus porta nisi quis eros. Nullam tristique mi feugiat arcu. Cras tempor luctus nibh. Phasellus vitae magna. Nulla porta quam eu risus. In bibendum. Nulla felis felis, scelerisque non, blandit ut, interdum in, pede. Sed ut tortor vitae justo pellentesque malesuada. Aenean sit amet dolor mattis lorem ultricies congue. In quis mauris. Ut blandit vulputate felis. Mauris dolor est, fringilla eu, laoreet sed, porta id, orci.

Sed a risus et nisl condimentum congue. Vestibulum tortor orci, auctor dapibus, fermentum vel, euismod ac, turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Fusce porta. In id justo. Duis fermentum pulvinar arcu. Aenean facilisis neque sit amet sem. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas sagittis turpis sed lectus. Donec iaculis eleifend arcu. Donec odio lorem, tincidunt ut, sagittis quis, lacinia sed, orci. Proin a sem sit amet pede eleifend dapibus.

Sed enim purus, vehicula eu, viverra quis, hendrerit et, metus. Phasellus lacinia viverra urna. Pellentesque rutrum luctus lorem. In placerat nibh eget risus ornare cursus. Etiam venenatis malesuada erat. Integer a mauris vel risus pellentesque tincidunt. Aliquam erat volutpat. Proin et orci. Nunc dignissim lacinia nisi. Mauris sapien purus, commodo at, suscipit nec, venenatis nec, dolor. Aenean faucibus est vitae risus. Aliquam eleifend sem et neque.

Vestibulum condimentum nisl vel erat. Vestibulum varius enim quis magna. Praesent hendrerit consectetuer nulla. Vestibulum vitae metus eu libero venenatis accumsan. Nam scelerisque mauris ut eros. Vestibulum mattis. Sed nisi dui, tempor ut, semper ac, feugiat ut, orci. Vivamus porttitor enim quis ante. Nulla quis diam. Quisque ut turpis nec sem scelerisque ullamcorper. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

You really need more??

Recycle IIS6.0 application pools from code

Works with IIS6.0 Windows Server 2003 SP1...

public static void Recycle(string host, string poolname)



(DirectoryEntry apppool = new DirectoryEntry(string.Format("IIS://{0}/w3svc/apppools/{1}", host, poolname)))





Microsoft Origami - I want one!

There's some serious buzz surrounding the Microsoft Origami Project and I eventually saw the video this morning after it was pulled from the Digital Agency that 'leaked' it.
I'm sure it's a conceptual device, 'accidentally leaked' to create some kind of buzz and excitement.  The continuity of the buttons give the game away for me but hey, if they make it, I'll buy it!  (Or rather five and sell the rest on ebay!)