Misc (RSS)

Misc

My Blog has Moved

I've made the switch to a new blog host.  You can find me now at jdixon.dotnetdevelopersjournal.com

I would like to thank Donny and the rest of the team for providing a great hosting site for me over the past year. 

It's been great.

Is Comment Moderation the Answer?

You know how funny life is sometimes?  Your program works great until you tell someone that it works great, then it crashes hard.  Or, in my case, I turned off blog comments because the spam was driving me nuts and no one has been leaving real comments anyway.  The very next day, I started receiving some good comments on a couple of my posts.  <Sigh>  So, I'm turning the comments back on, and will just have to zap the spam as it comes in.

On a better note, I noticed that the .Text engine may have a solution.  Apparently they have a version that features comment moderation, along with one of those Security Code features with text inside a bitmap.  This might annoy some users, though.  A couple of blogs (http://www.peterprovost.org/archive/2004/08/13/1763.aspx, http://scottwater.com/blog/archive/2004/08/08/12888) mention negative feedback.

So what do you think?  Is comment moderation the answer, or should we put up with having to delete comment spam multiple times a day?

Comment Spam Stinks!

Well, it finally happened.  Because of the enormous amount of comment spam that I have been receiving, I have joined the ranks of those that have disabled blog comments.  If someone wants to comment on one of my posts, please send the comment to me via the "Contact" option under "My Links."

I am very disappointed that this has become necessary, but I have been deleting spam from my blog three or four times a day.  Spammers won't be content until they have ruined blogs, just like they have ruined email.

Critical Sections in SQL Server

Many of us more experienced (NOT older) techies like to speak of learning things the hard way.  This definitely applies to me and the way I learned about SQL Server 2000.  I've had to learn it all on the job, on an as-needed basis.  This means that there are gaps in my knowledge.  Every once in a while, I get to learn something about SQL Server that I never knew before.  This time, it was the fact that SQL Server supports critical sections.

For those of you that may not know this term, a critical section is a piece of code that can be safely run by only one process at a time.  In a multi-threaded application, this applies to each individual thread; only one thread can safely execute a piece of code at a time.  The term “Critical Section“ is common in languages with roots in C or C++.

I found myself with just this situation with a stored procedure.  I found that there are two system stored procedures, sp_getapplock and sp_releaseapplock, that implement this concept.  Here is an excerpt from SQL Books Online:

sp_getapplock

Places a lock on an application resource. 

Syntax

sp_getapplock [ @Resource = ] 'resource_name',
    [ @LockMode = ] 'lock_mode'
    [ , [ @LockOwner = ] 'lock_owner' ]
    [ , [ @LockTimeout = ] 'value' ]

Arguments

[@Resource =] 'resource_name'

Is a lock resource name specified by the client application. The application must ensure the resource is unique. The specified name is hashed internally into a value that can be stored in the SQL Server lock manager. resource name is nvarchar(255), with no default.

[@LockMode =] 'lock_mode'

Is a lock mode. lock_mode is nvarchar(32), with no default, and can be one of these values: Shared, Update, Exclusive, IntentExclusive, IntentShared.

[@LockOwner =] 'lock_owner'

Is the lock owner. lock_owner is nvarchar(32) and can be Transaction (the default), or Session. When the lock_owner value is the default, or when Transaction is specified explicitly, sp_getapplock must be executed from within a transaction.

[@LockTimeout =] 'value'

Is a lock time-out value, in milliseconds. The default value is the same as the value returned by @@LOCK_TIMEOUT. To indicate that lock requests that cannot be granted immediately should return an error rather than wait for the lock, specify 0.

Return Code Values

>= 0 (success) or < 0 (failure)

Value Result
0 Lock was successfully granted synchronously.
1 Lock was granted successfully after waiting for other incompatible locks to be released.
-1 Lock request timed out.
-2 Lock request was cancelled.
-3 Lock request was chosen as a deadlock victim.
-999 Parameter validation or other call error.

Cool.  This is exactly the kind of “semaphore-lock“ that I cut my teeth on.  Of course, it turns out that I didn't really need this.  I discovered a better way to implement my task.  However, I thought that I would pass this along, since I had never heard of it before.  Maybe it will help someone else.

Best Kept Secrets in .NET

I sure that many of you are just as busy as I am.  You probably don't have time to read all of the books that you need to read.  That's one of the reasons that I like Best Kept Secrets in .NET.  This book, written by Deborah Kurata and published by Apress, is a collection of useful tips instead of an in-depth tutorial.  You can pick it up, read a few pages, and put it back down again.  (I managed to read the entire book while getting ready for work each morning.) 

Deborah is a frequent contributor to CoDe magazine, which I always read, so I had high expectations.  While I think that the tips and techniques don't always qualify as “best kept secrets“, they are all very valuable.  In fact, I believe that all junior programers should be required to read this book.  Here's a small sample of the topics in the book:

  • 12 ways to search for code
  • Shortcut keystrokes
  • Accessing External Tools
  • Windows Forms techniques
  • Typecasting
  • Aliasing Data Types
  • Regular Expressions
  • ADO
  • “Defensive“ Development

I have to admit that I already knew most of these techniques.  Why do I like this book then?  Because I've been using .NET exclusively for over 3 years now, and I've had to learn this information the hard way.  This is why I'm recommending the book to all junior programmers and those less familiar with .NET.  This book will help you learn to use Visual Studio and .NET to get the most productivity out of your programming time.

Interesting PC Magazine Articles

I've was reading PC Magazine tonight, and I came across two very interesting articles.  I thought they were worth passing along.

The first article is called “No-Cost Ad Blocking” and is written by Sheryl Canter.  (You can read her on-line version here.)  It shows you how you can block web page ads, for free, by using a Proxy Automatic Configuration (PAC) file.  Sheryl's Web page explains the concept, and includes links to freely downloadable files that implement this.  This is a good read.

The second article discusses a product called SeePassword that can display passwords that are hidden by asterisks or dots in Windows forms.  I've seen this kind of thing before on Windows 9x, but I thought NT and XP weren't vulnerable to this.  I guess I was wrong.  You should also check out the View Passwords bookmarklet on www.squarefree.com for another way to reveal passwords.

A First Look at SQL Server 2005 for Developers

I know you probably think I've fallen off the planet, but I've just been busy; preparing to teach a class, trying to keep multiple clients happy, and trying to learn SQL Server 2005.  (I've also got to pay attention to my family sometime, don't I?)  Anyway, the SQL Server 2005 Beta is publicly available now, and there is a lot of new stuff to learn.

Jon Box let me borrow a book that someone gave him (I would like to mention him, but I forgot his name.  Maybe Jon can remind me.)  The book, entitled A First Look at SQL Server 2005 for Developers, is published by Addison Wesley.  It's authors are Bob Beauchemin, Niels Berglund, and Dan Sullivan.  If you are a fan of SQL Server, you need this book!  SQL Server 2005 has quite a few changes in store for us, and you WILL need help learning to take advantage of all of them.  Here is a short list:

  • Inclusion of the .NET 2.0 Framework (You can write stored procs, functions, and triggers in any .NET language.)
  • T-SQL enhancements (That dang TOP X statement will FINALLY accept a variable, Stored procs now have support for recursion, and more.)
  • User-defined Aggregates
  • Enhanced Security
  • Statement-level Recompilation (!!)
  • Triggers on DDL statements (You can fire a trigger when someone drops a table from your database!)
  • XPath 2.0 (If you want me to babble on forever, just ask me about XML and XPath.)
  • XQuery 1.0 (A whole new way to query XML data.)
  • XML as a data type (Whoo hoo!  XML is no longer a large string of text.  It can be queried directly.)
  • Other new data types (You can now use .NET UDFs; even rich Object Hierarchies.)
  • Web Service Hosting
  • Notification Services
  • Service Broker (Message Queues)

That's enough for now.  While by no means exhaustive, this list gives you the idea.  SQL Server 2005  is not a mere upgrade; it is a greatly enhanced product.  (Did I forget to mention the expected performance improvements?)

Which brings me back to my point (yes, I had one):  If you are looking for a great book to help you learn these new features, well, remember this post's title.

SQL Guru starts blogging

As .NET developers, we all must understand SQL.  This trend will continue in the future, especially with the release of SQL Server 2005 (Yukon) with it's use of managed code.  For those of us in need of enlightenment, there is a new blog that contains lots of useful information:

Kimberly L. Tripp
Blog
http://www.sqlskills.com/blogs/Kimberly/
Web: http://www.sqlskills.com

According to Jon Box, she is one of the premier SQL gurus.  I have been reading her blog lately, and I agree.  I've been a DBA for many years now, and I still am learning things from her.  I highly recommend her sites.

Alternate Data Streams

Another topic I came across while trying to read myself to sleep is Alternate Data Streams in NTFS.  Apparently, this feature is provided for compatibility with Macintosh Hierarchical File System resource forks.  Whatever the reason, they exist and I wanted to tell you about them.

Open a command window and try the following:

Create a file called “names.txt“ that contains my name:
echo Jerry > names.txt

Prove that the file contains my name:
more < names.txt

Add my wife's name to the file, in an alternate data stream:
echo Tammy > names.txt:wife

Retrieve the contents:
more < names.txt
more < names.txt:wife
There are now two separate sets of data in this one file.

You can access the default stream in two ways:
more < names.txt
more < names.txt::$DATA

I do not know how many streams you can have in a single file.  I have sucessfully added three streams myself. 

As you can imagine, this poses a bit of a security threat.  A malicious user can “hide” data, such as script, in your files.  Most people would never think to look into a file's alternate data streams.  A quick scan of the net shows that many anti-virus programs don't either.

Dotless IP Addresses (and other IP obfuscations)

I came across the concept of dotless ip addresses recently while enjoying some “light” bedtime reading.  After doing some surfing on the net, I discovered some information that I would like to share.  I am going to show you many different ways to tell your browser to navigate to Yahoo's web site.  (NOTE:  all of the following methods work in some browser, but not all methods work in every browser.)

“Normal” Addresses
DNS:  http://www.yahoo.com
IP:  http://216.109.117.109

Dotless Addresses
1).  Convert each decimal octet to hex: 
      216 = D8
      109 = 6D
      117 = 75
      109 = 6D
2).  Make one hex number out of them:
      D86D756D
3).  Convert back to decimal:
      3631052141

So, you can get to Yahoo via http://3631052141

You can also calculate this with the formula:
      dotless ip =
            (octet1 * 16777216)  +
            (octet2 * 65536) +
            (octet3 * 256) +
            (octet4)

Weird Alternatives:
Octal:  http://0330.0155.0165.0155
Hex:  http://0xD8.0x6D.0x75.0x6D
Hex:  http://0xD86D756D

and finally, to really confuse things, mix the methods together:
      http://0330.0x6D.117.0x6D

Why do we do this to ourselves?     

Pagination in HTML Reports

There are many times when I have to create reports in Web Pages.  These reports typically span multiple printed pages, and each page needs to have a common header.  How can this be done easily?  CSS comes to the rescue:

<table style="table-layout:fixed">
    <colgroup>
        <col width="150"/>
        <col width="100"/>
        <col width="150"/>
    <colgroup>
    <thead style="display:table-header-group">
        <tr>
            <td>Header column 1 (150)<td>
            <td>Header column 2 (100)<td>
            <td>Header column 3 (150)<td>
        <tr>
    <thead>
    <tbody>
        <tr>
            <td>Body column 1 (150)<td>
            <td>Body column 2 (100)<td>
            <td>Body column 3 (150)<td>
        <tr>
    <tbody>
    <tfoot style="display:table-footer-group">
        <tr>
            <td>Footer column 1 (150)<td>
            <td>Footer column 2 (100)<td>
            <td>Footer column 3 (150)<td>
        <tr>
    <tfoot>
<table>

 

Use “table-layout:fixed” to make a statically-sized table (for speed), and use “colgroup” and “col” elements to provide the column sizes.  This makes the report render very quickly.  (No dynamic table sizing.)

Use “display:table-header-group” in the “thead” element, and “display:table-footer-group” in the “tfoot” element to make the header and footer appear on every page.

Try it!

.NET Game Programming

Have you ever wanted to program a game in .NET, but didn't know where to start?  I picked up a cool book recently that helped me do just that.  “.NET Game Programming with DirectX 9.0”, by Alexandre Santos Lobao and Ellen Hatton, teaches you how to get started programming games.

This book takes you through the entire development process, from the initial game proposal to the final product.  Along the way, many concepts are explained; graphics in general, GDI+, and Managed DirectX 9.0.  Yep, Managed DirectX 9.0.  I really enjoyed programming my first DirectX project using .NET.  No APIs required.

Games presented include a Tretris clone, a Snake clone, and a vertical scolling game similar to Atari's River Raid.  Very cool programming.

My intro to blogging...

I am one of those people that believes that everyone knows what I know, and that everyone has done what I am doing, so why should I start a blog?  Well, one of my best friends (and currently a co-worker), Jon Box keeps telling me that I should. Whenever I tell him of some new thing that I am trying, he says, "See? That would make a good blog post." So, check back in a few days to see some of what Jon is talking about.