March 2005 Entries

SQL Server Rant

 

So I was finishing up a stored procedure this morning, saved it and then noticed that once the editor closed that I didn't prefix this particular stored procedure as I had all my previous to match. No problem, right-click on the stored procedure in the list and select “Rename” which will allow you to edit its name, it will confirm that you want to change it and it's a done deal, right? Nope, if you open the stored procedure back up you will notice that it didn't change its name 'internally' within the stored procedure; you have to manually edit it there as well. I don't know if this is a documented problem or not, is anyone else aware of this issue?

CLR Internals

 

The May issue of MSDN magazine came in the mail today and there is a great article inside called Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects. This article is definitely not for the faint of heart, but I absolutely love this stuff. Hanu Kommalapati and Tom Christian go into great detail discussing items such as LoaderHeaps, High and Low Frequency Heaps, the SOS debugger and how the ClassLoader creates the Method Slot Table to name just a few. Oh yes, you will learn how virtual method dispatching works from the ClassLoader's point of view - you know you were always curious. I will read this again tomorrow so it can all soak in, but if you're interested in any of the above this article is definitely worth your time.

The Shelf Life of Google

 

I can't help but wonder, with Google continually producing more and more products related to their search technology, where will it end? I love Google as much as the next person (probably more) and with the competition in high demand I don't think we'll see an outage anytime soon. MSN has been producing some great integration tools for their search service that are outstanding - I love the fact that I can get my search results in an RSS format. That said, where do we draw the metaphorical red-line? Personally I think we will see much more integration with artificial intelligence in terms of searching. We've seen this already present with the recently sold search provider Ask Jeeves which has been around for years. If they are lucky, they will never perfect the search though, because to only make it better keeps them in business - such is the same reason we replace light bulbs every year. What are your thoughts?

Dealing with the phone company

 

So I went to check out my phone bill online tonight and noticed an additional charge of $18.95 and the detail line was for MSN. I decide to call up Qwest to discuss the charge and while I am waiting on hold I decide to check my bill from the previous month. Interestingly enough there was an identical charge for MSN of $18.95. I quickly decided to check my January bill, which was clear of any erroneous charges. Side note - I've never used MSN before at all. I recently signed up for the AutoPay feature on the Qwest website and "accidentally" forgot to check my February bill - my mistake.

Once I am able to talk to a Qwest representative they confirm that they are not in fact charging me for the service and it is MSN issuing the charge (duh!). The representative told me I would need to contact MSN to discuss this issue because Qwest is not able to remove the charge. She then proceeded to give me the MSN number which I dialed promptly. The MSN representative could not find an account that was assigned to me and proceeded to tell me that I needed to call Qwest back and have them do a three-way phone call with MSN to 'dispute' these charges. I asked why we couldn't just do the three-way call now since I already had MSN on the line; they said there weren't 'able' to do that - whatever.

Now I called Qwest back, gave them the MSN number to call and we suddenly found ourselves in a three-way phone conversation in which I had to explain myself for the third time. Finally, after 60 minutes and three different phone conversations with two different companies my account is credited. I've learned to watch automatic online billing a little closer, has anyone else had problems with this type of thing?

Fun with the CodeDOM

 

I just realized tonight that it's been quite awhile since I've had a blog post. Things at work have kept me rather busy but they are finally starting to settle down now. I was talking to Tim Gifford earlier today about the use of CodeDOM. I decided to put together a little sample that shows you how to generate code on the fly. The example was just thrown together so there are obviously many modifications that can be done to clean this up, an exercise that will be left up to the reader. It's important to understand how the CodeDOM works if you ever build any tools that need to generate code. I have to admit that one of the strangest property values throughout the CodeDOM is the BracingStyle of the CodeGeneratorOptions class. The default string value is “Block”, which generates code with a Java style format where the beginning bracket doesn't get its own line, if you prefer a new line for your beginning brackets the value you use is “C”, why not just use an enumeration? Anyway, here is a sample function to generate C# code:

You need follow:
using System;
using
System.IO;
using
System.CodeDom;
using
Microsoft.CSharp;
using
System.Reflection;
using
System.CodeDom.Compiler;

// .....

public void Generate(string file)
{
Stream s
= File.Open(file, FileMode.Create);
StreamWriter writer = new StreamWriter(s);

// code generator
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeGenerator gen = provider.CreateGenerator(writer);
CodeGeneratorOptions genOpt = new CodeGeneratorOptions();
genOpt.BracingStyle = "C";
CodeSnippetCompileUnit compUnit =
new
CodeSnippetCompileUnit("using System;");
gen.GenerateCodeFromCompileUnit(compUnit, writer, genOpt);
writer.WriteLine();
// namespace decl.
CodeNamespace nmspace = new CodeNamespace("DeveloperNotes");
// public class
CodeTypeDeclaration cls = new CodeTypeDeclaration();
cls.Name = "Example";
cls.IsClass = true;
cls.TypeAttributes = TypeAttributes.Public;
writer.WriteLine();
// add class to namespace
nmspace.Types.Add(cls);

// private variable
CodeMemberField member =
new
CodeMemberField(typeof(string), "name = \"Nick\"");
member.Attributes = MemberAttributes.Private;
cls.Members.Add(member);
// public constructor
CodeConstructor constructor = new CodeConstructor();
constructor.Attributes = MemberAttributes.Public;
cls.Members.Add(constructor);
// public property
CodeMemberProperty prop = new CodeMemberProperty();
prop.Attributes = MemberAttributes.Public;
prop.Type = new CodeTypeReference(typeof(string));
prop.Name = "Name";
prop.HasGet = true;
CodeSnippetExpression cse =
new
CodeSnippetExpression("return name");
prop.GetStatements.Add(cse);
cls.Members.Add(prop);
// Main method
CodeMemberMethod main = new CodeMemberMethod();
main.Name = "Main";
main.ReturnType = new CodeTypeReference(typeof(void));
main.Attributes = MemberAttributes.Public
| MemberAttributes.Static
;
CodeSnippetStatement css0 = new CodeSnippetStatement();
css0.Value = "Example ex = new Example();";
CodeSnippetStatement css1 = new CodeSnippetStatement();
css1.Value = "Console.WriteLine(\"My name is: \" + ex.Name);";
CodeSnippetStatement css2 = new CodeSnippetStatement();
css2.Value = "Console.Read();";
main.Statements.Add(css0);
main.Statements.Add(css1);
main.Statements.Add(css2);
cls.Members.Add(main);
// output contents
gen.GenerateCodeFromNamespace(nmspace, writer, genOpt);
// clean up
writer.Close();
s.Close();
}

Generates the following code:

using System;
namespace
DeveloperNotes
{

public class Example
{

private string name = "Nick";

public
Example()
{
}

public virtual string Name
{
get
{
return name;
}
}

public static void Main()
{
Example ex
= new Example();
Console.WriteLine("My name is: " + ex.Name);
Console.Read();
}
}
}