Wednesday, February 28, 2007

Events not showing up in EventLog

At some point ASP.Net web applications stopped being able to log to the event log. There are a few ways this can be fixed. Follow one of the suggestions in this tech note from Microsoft: http://support.microsoft.com/kb/329291 Give Network Service or ASP.Net permissions using regedit.exe (not regedit32 as it is broken). Give permissions to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog and right-click. Choose Security Permissions. Give the account that your application runs under Full Control of the key and all subkeys
  • If deploying in IIS 5 (for example: Windows XP Professional) Give the ASPNET account Full Control.
  • If deploying in IIS 6 (for example: Windows Server 2003) Give the NETWORK SERVICE account Full Control. NOTE: If running your application pool under a different user than NETWORK SERVICE, then give that user account Full Control instead of NETWORK SERVICE. This is the user that the process will run under.
Warning: Option 2 doesn't seem to help if application is trying to write to Security log. If you create the key manually as Option 1 suggests you will need add another registry key as explained in the following entry I wrote. http://justgeeks.blogspot.com/2007/10/aspnet-and-eventlog-event-id-issues_1860.html

Tuesday, February 27, 2007

Java Application Server start and stop manually

Starting the Java Application Server that comes with Java Studio Enterprise 8 by running the start-domain is not recommended due to parameters that are expected by the batch file. Consequently the batch file hangs. To properly start the Java Application Server, open a command prompt and type: Asadmin start-domain

To properly stop the Java Application Server, open a command prompt and type: Asadmin stop-domain

Thursday, February 22, 2007

.Net Caching Rocks!

OK, I can't believe how cool .Net's built in Caching is. Here is the scenario. I need to query an Oracle database that I don't have anything but select permissions on. So, executing stored procedures and definitely can't create a stored procedure. So, what am I to do? Embed the query in code? That may be fine for small queries, but what if you query is quite long and complex. Sure, technically it can be put in the code, but who wants to maintain it. My solution was to put it in a file that is read from the file system at runtime. The problem is that the file system is hit everytime. So, I decided to cache it using the caching built into .Net. Below is my method that does this. The part that is so cool is that I can set a dependency for when an item in the cache is removed. As it turns out, one of the dependencies is a filename and path. If the file changes the cache is automatically notified. That is magic! :) using System.Web.Caching; .... public string LoadSQL(string filename) { object sqlObj = HttpContext.Current.Cache.Get(filename); string sql = string.Empty; if (sqlObj == null) { string path = HttpContext.Current.Request.PhysicalApplicationPath; string filenameAndPath = string.Format(@"{0}SQL\{1}", path, filename); using (StreamReader reader = new StreamReader(filenameAndPath, true)) { sql = reader.ReadToEnd(); System.Web.Caching.CacheDependency dependency = new CacheDependency(filenameAndPath); HttpContext.Current.Cache.Add(filename, sql, dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.High, null); return sql; } } else { sql = sqlObj as string; } return sql; }

Wednesday, February 21, 2007

SQL 2005 ROW_NUMBER()

SQL Server 2005 no makes it easy to do paging of results and every n rows queries now that the row number can be obtained without using a temp table.

The new functionality is given by ROW_NUMBER(). Here is an example that returns every other row regardless if rows have been deleted, missing pks in the sequence, etc:

select Employee_number, myrownum from

(

select

Employee_number,

row_number() over (order by sc.FIRST_NAME asc) as myrownum

from

person

) as temp_person

where

myrownum % 2 = 0

order by myrownum asc

NOTE: the LAST line it is very important if you want to see the rows returned in the order of the row numbers.

Thursday, February 1, 2007

Getting to the instance of your object when using ObjectDataSource

Sometimes when using ObjectDataSource you need to have access to the object that ObjectDataSource is using. Maybe you have a custom constructor you need to call, maybe you need to hook up an event handler, etc.

Once again, ASP.Net 2.0 comes through.

The ObjectCreated event on ObjectDataSource:

protected void ObjectDataSource1_ObjectCreated(object sender, ObjectDataSourceEventArgs e)

{

BLL bll = (BLL)e.ObjectInstance;

bll.haveToSetThis = "not really";

}

You should also look at ObjectCreating event since can be used to actually create the instance of the object.