20. February 2006 15:41
optionsScalper will be giving what is sure to be an interesting presentation on F#.NET at the Wisconsin .NET user's group tomorrow. optionsScalper has a very serious math background, a scientific mind, and an excellent singing voice. I like to think of him as someone who's putting the Science back in Computer Science.
He has piqued my interest in F# so I hope to have it installed and working before the presentation so I can follow along. I won't attempt to describe F# until I've written some, suffice to say it is a different programming model than the stack-based imperative languages most of us are familiar with and thus presents a paradigm that is much more friendly to certain types of problem solving.
13. February 2006 15:15
I have a small web site I was looking into converting to ASP.NET 2.0 for various reasons *cough resume cough couh* however due to environmental restrictions (corporate politics, not EPA) I have to use MySQL as the data store, and there is an existing schema which is absolutely nothing like the schema the default ASP providers use. This provided the perfect excuse to dig into some internals and see about providing some Providers.
Why would one go through the trouble of implementing these interfaces? First, as you'll see, its pretty easy. Second, by doing this you can still use all the great plumbing for role-based security and the "Login" and "User" family of controls that ship with ASP 2. By looking through my machine.config I can see that I'll need to create and configure instances of two abstract classes: System.Web.Security.MembershipProvider and System.Web.Security.RoleProvider. There are some intermediate classes you could choose to inherit from like SqlMembershipProvider that might save you some time but in my case it seemed quick enough to start at the base class. Intellisense and the compiler will tell you what methods you need to override. For example, MembershipProvider requires an implementation for ValidateUser such as:
public override bool ValidateUser(string username, string password)
bool valid = false;
EmployeeDataAccess dao = new EmployeeDataAccess();
Employee e = dao.FindByLoginAndPassword(username, password);
Simple enough. If you decide to do this, you may wish to set some breakpoints in methods like RoleProvider.GetRolesForUser and run through your app.
public override string GetRolesForUser(string username)
SecurityDataAccess dao = new SecurityDataAccess();
List<string> roles = dao.GetRolesForUser(username);
In my case there is a small performance hit for running this method. ASP calls this method to validate your access to pages, proces any LoginView controls trim asp:Menu items if you have securityTrimming enabled, and user code could always call Page.User.IsUserInRole(""); sliding expiration in the ASP.NET cache is a good idea here. Finally, you just need to tell your web application to use your custom providers. Supposing my security data store is called "IDMS" and my classes are named accordingly, here are my web.config settings:
<roleManager enabled="true" defaultProvider="IDMSRoleProvider">
<add name="IDMSRoleProvider" type="IDMSRoleProvider" />
So, as you can see, its easy to implement classes to plug into Asp.NET security.
9. February 2006 18:30
A former client called me today to ask if I knew anyone with X,Y,Z skills who was looking for a work. They weren't interested in consultants at this point so I said I didn't off-hand and directed them to the Wisconsin .NET user's group job board at the above URL. Note that none of these are entry-level jobs that I can tell. Employers: you are burning the future to stay warm. You are assuming someone else will do you the favor of training the recent grad and you can scoop them up when they're no longer green. Everyone else is making the same assumption and the symptom is kids not going into CS related degree programs. The result is the President noting in his state of the union address that congress needs to let us import "smart folks" for "Jobs that are having trouble being filled here."
4. February 2006 17:59
A lot of developers working with these great modern garbage collected single-inheritance object oriented programming languages on big powerful servers may go their whole career without actually seeing an OutOfMemoryException. This will happen from time to time on the compact framework and I'm happy to say I typically pay attention to what I'm doing and my hard to track down bug from yesterday is my first OOME. I have a sync process that merges data into SQL CE 2. To try to squeeze blood (performance) out of a rock (SQLCE 2.0) it prepares and caches update and insert commands. Here's a small piece of that code:
System.Data.DataTable schemaTable = dr.GetSchemaTable();
dbCommand = DataHub.Database.GetCommand(GetUpdateTemplate(ref schemaTable, pk, changeColumn), DataAccessObject.CONNECTION_STRING);
foreach (System.Data.DataRow row in schemaTable.Rows)
columnName = (string)row["ColumnName"];
int columnSize = (int)row["ColumnSize"];
dbParameter = new SqlCeParameter(
"@" + columnName,
dbParameter.Precision = Convert.ToByte((short)row["NumericPrecision"]);
dbParameter.Scale = Convert.ToByte((short)row["NumericScale"]);
int columnOrdinal = (int)row["ColumnOrdinal"];
object pVal = DBNull.Value;
pVal = dr.GetValue(columnOrdinal);
dbParameter.Value = pVal;
This worked for a long time until someone decided that a column of type ntext should be replicated. The column size for a field of type ntext happens to return something like 580million bytes. When the code tries to set the parameter value, it finds it can't allocate that much space. The maximum stack size in the compact framework v1 is 640k (reminds me of MS-DOS low memory, no one will ever need more than 640k); 640kb * 1024b/kb = 655,360bytes, or "not enough" and the OutOfMemoryException is thrown.
I feel a little sorry for anyone building a custom sync process using SQL CE. SQL Mobile is much nicer but does not remove the potential for things like this to happen. I have a project I'm working on which I'll open-source IF I get it done. I say if becuase I have occasionally announced some wacky plan here only to be distracted by a shiny object and said project dies on the vine.
Speaking of stack size optionsScalper was telling me about F# and how .... look, a penny!