Tuesday, September 02, 2008
Thursday, August 07, 2008
Writing to Event log with ASP.Net and Enterprise Library
I recently had a problem writing to the event log from my application. I had configured the application to use the Logging Application Block from the 3.1 version of the Microsoft Enterprise Library and followed the walk-through in the documentation to log exceptions to the Application Log, but nothing was appearing.
I had amended the code so that it always through an exception on clicking a test button, and stepping through the code, I could see that Log.Write was being called and no error was raised from this call.
A quick search on Google suggested that this was a permissions issue for the ASP.Net account, so I added the following key:
HKLM\System\CurrentControlSet\Services\EventLog\Application\<my app name>
I granted full control to the ASPNET account to this key and amended the source property of my trace listener to <my app name> using the Enterprise Library Configuration Manager.
I now get events recorded in the Application log and their source is set to <my app name> so it is easy to filter them for the events I want.
Tuesday, March 04, 2008
Code Access Security For Child AppDomain
I recently configured an existing application to use ClickOnce deployment. All seemed to go well until I tried to run the application, whereupon it threw an exception on a line that had previously been working perfectly:
AppDomain childDomain;
childDomain = AppDomain.CreateDomain(ChildAppDomainName);
//Following line throws exception
childDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
The exception was:
{"Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}
The application was configured to run as FullTrust. To cut a long and frustrating story short, It turned out that the security settings were not being propagated to the child AppDomain. I changed the code to the following:
AppDomain childDomain;
Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
Evidence childEvidence = new Evidence(baseEvidence);
childDomain = AppDomain.CreateDomain(ChildAppDomainName, childEvidence, AppDomain.CurrentDomain.SetupInformation);
This allowed the child AppDomain to inherit the settings from the parent domain and everything worked as expected once more.
Friday, February 29, 2008
Check for existence of DB objects
Some queries I find useful to add before the Create/Alter Statements in SQL Server.
--Constraints
IF EXISTS(
SELECT NULL FROM INFORMATION_SCHEMA.Constraint_column_usage
where table_name ='MyTable'
and constraint_name = 'FK_COl1')
--Check existence of stored_proc
IF EXISTS (SELECT NULL
FROM information_schema.routines r
WHERE r.specific_schema = 'dbo'
AND r.specific_name = 'MyProc')
--Check column exists
IF NOT EXISTS (
SELECT NULL
FROM information_schema.columns
where column_name='Col1'
AND table_name ='MyTable'
and table_schema='dbo')
IF not EXISTS(
SELECT NULL from sys.all_objects ao
INNER JOIN sys.extended_properties ep on ao.object_id = ep.major_id and ep.name ='MS_Description'
where ao.name ='FK_key_name')
Friday, January 25, 2008
Disable full screen video on Dual monitor setup
- Bring up display properties from control panel
- Click Settings
- Click Advanced
- Click Quadro NVS 120 M (Nvidia specific)
- Click Start NVidia control panel
- Click Video and Television
- Click Modify full screen options
- Set "When watching video content" to Only show it in my viewing application
Thursday, January 03, 2008
Soap Extensions in web forms client
<system.web>
<webServices>
<soapExtensionTypes>
<add type="myCompany.myProject.WebServices.SoapExtensions.CompressionExtension,myCompany.myProject.CompressionExtensionLib"
priority="3" group="High" />
soapExtensionTypes>
webServices>
system.web>
The first part of the type is the fully qualified class name, the second part is the namespace.