h1

MS Access Query Truncation Problem

January 19, 2012

There’s been a small change to the way MS Access works from the ’97 to the 2010 version that can cause some serious issues.

Consider this query “Select * From Table1″ . What happens? In both versions, it will run just fine. However, when importing this command through any database connection, say OLEDB, it won’t work. Instead, what’s fed into 2010 is “able1″.

What’s happening? For database connections, table names are required to be square-bracketed. A simple fix.

Just use “Select * From [Table1]” instead.

h1

Connection problem or invalid MMI code workaround

December 13, 2011

I recently encountered this. No calls would go through, even though it was working yesterday.

The fix:
– remove the battery
– remove the sim card
– reinsert both
– (re)start your phone.

h1

SQL Sproc Gotcha

December 8, 2011

It’s easy to mistake the SQL Sproc syntax

ALTER PROCEDURE [dbo].[fooBar]
(
)
AS
-- etc
RETURN  @Success

With this. Note the BEGIN and END statements. It generally works for shorter queries, but for longer ones, you begin to get baffling SQL syntax queries, where sometimes it will execute the ALTER PROCEDURE, but things like changing the whitespace, reverting it, and executing it again will fail.

ALTER PROCEDURE [dbo].[fooBar]
(
)
AS
BEGIN
-- etc
RETURN  @Success
END

h1

Contracting: Tales of Being Short A Project Manager

December 2, 2011

Dipping your toes in

As a young developer growing up, it’s easy to take all kinds of things for granted. For example, a testing and production environment that aren’t close, but instead, exactly the same. The ability to ask for a copy of Visual Studio without balking at it’s price in sticker-shock. Or a dedicated tester.

It’s easy to get caught up browsing through contracting websites and fancy being a solo contractor on your spare time. You forget to consider how tired you actually are when you drag yourself home from your real job, how much time it really takes to do the dishes, how much of a procrastinator you are, and even possibly how you’ll drop near everything to be immersed in the latest Elder Scrolls game. Instead, you wrap your head around how much money you think you’ll make in your spare time doing what you already love.

You enthusiastically tell your friends who give a shrug, explain to your Uncle Fred how it isn’t a get rich scheme,  try to unconvince your un-computer-savvy Aunt Bethelida to learn programming just so they can try it too, and ward off concerns from family members who believe that because your contracting involves a computer, it is a demonic form of giraffe-sacrifice and should be shut down immediately.  Perhaps you manage to get excellent advice from all your buddies who dipped their toes in, and possibly you even find some templates for things like contracts, invoices, and various other communications. You feel disappointed at the back-and-forth between you, your friends’ friends’ lawyer, your client, their boss, their HR department, and their accounting department that takes months before the final, final contract is sent, looking much different than what you had expected. And if you’re like me, you succumbed to your human tenancy to skim and well… just shot yourself in the foot. Multiple times.

Baited and hooked

All sorts of questions arise like, how does the signature dates affect the dates already written on the contract’s staticly-dated timeline? Does that mean that you really only have a few days to deliver item X or that it is even, that it is already overdue? How exactly will payments come? And when will they come, since it’s been months since task X and your client’s manager’s manager is preoccupied. Suddenly, you realize that depending on the terms of your contract and employment, you may are actually making 30% less of your revenue due to taxes – and the fines for not paying them, because ignorance is no excuse. And what about health care, benefits, sick and vacation days, hm…

But, if you’re like me, that’s only the tip of the iceberg of why you miss your project manager to death.

No matter how good you think you are with client relations, you always seem to wonder if you worded things correctly for such an important legal matter. Is it too bossy? Is it even correct? Does it abide by the contract? There’s no second pair of eyes to do it, and you’ll be the one answering all the questions, inquiries, papers, forms, nonconstructive criticism, and time sheets.

You now manage your own schedule, which in some ways is nice, but in others, you miss that gentle reminder to get back to work when you find yourself engrossed in the latest TV series, and then even procrastinating with re-runs.

You begin your work and perhaps you find the lack of office noise enthralling, but at the same time, you miss the occasional passerby’s surely prying eyes which kept you working, out of fear they’d discover your love for FarmVille. If you’re like me, you find that programming on your couch, on your porch, and even in a coffee shop is enlightening. But when you make a mistake, you have no one to blame but yourself. When you short sight something, it’s your own fault. When you misunderstand, over budget, or encounter scope creep, everything falls on your lap. Where a project manager might help you keep a clear perspective on things, manage that creeping scope caterpillar, and lessen the blow of your own shortcomings, you have no one. Of course, it never was the project manager’s fault for any of these things, and you probably knew that already, but they kept it all under wraps and off your shoulders.

But what you really, really miss is what your project manager did best – sitting down with the clients and figuring out what they are asking, what they really mean, what they really need, what fits under the budget, the easiest way to do it, and what they will ask for later. As a self-contractor, you get stuck commuting or telecommuting to your client’s sites, map in hand, and wondering how to put your gas on the bill. You feel helpless as you wait for everyone to be available for the meeting even though it was extensively planned, while wading through all the wary, suspicious glances of you as an outside. You got lost in the building. You forgot a paper. You just now realize your only pen doesn’t work. You parked where you’re weren’t supposed to,. And you come home eight hours later in rush-hour freeway traffic feeling overwhelmed, and with a notebook full of your own notes that you can’t decipher.

In your communications, you feel helplessly lost as terms like ‘database’, ‘software’, ‘on-line’, ‘desktop’, ‘excel’, and ‘report’ are interchangeably used. But you can’t blame your clients, you created your software to be so seamless and easy that they didn’t have to worry about those terms. When you ask for an explanation of their request, they can only repeat the same vague request, that in your mind means “change everything“. You ask for an example and receive a squiggle comparable to Jack’s attempt to request ‘Chipotle’ If you’re lucky, you stumble onto the approach of providing the entire product, asking them to point to a specific thing, and tell you “make this X a Y”.

Contracting: When it’s worth it

If you’re like me, you find yourself looking at the video games, new computers, plasma television sets, and imagining being able to afford it all along with a pair of working prescription eye glasses. But at the end of the day, you pay your bills, and settle in for a Redbox movie and McDonalds Dollar Menu item, paid mostly in pennies. Your quality of life is really no different than it was before.

Contracting is a lot of work and requires a lot of know-how, and not just the technical kind. But between all the stress headaches and deadline midnight latte’s, if you enjoy what you do and who you do it for, it’s worth it. So, if you’re considering contracting as a beginner, don’t tease yourself with fictitious dollar signs and dreams of a sixth computer. Be realistic, expect your money ten tames later than you imagined, and consider setting some extra cash aside for that inevitable life emergency that will occur until then – say, an accident, a sprained ankle, or an embarrassing trip to the vet because your dog likes their squeaky ball a little too much.

A special thank you to J.H,, MBA and D.W.

h1

Iterating stored procedures in SQL

November 30, 2011

You can iterate the procedures and functions in your database with a query like this:

SELECT * 
FROM  INFORMATION_SCHEMA.ROUTINES

Or, if you only want to see the stored procedures and functions that you have created yourself:

SELECT specific_name, routine_type, created, last_altered 
FROM INFORMATION_SCHEMA.ROUTINES
where
substring(specific_name, 1,3) != 'sp_'
and substring(specific_name, 1,4) != 'sys_'
and substring(specific_name, 1,7) != 'aspnet_'

h1

Copyright and You

October 19, 2011

This article only covers the US copyright law and should not be used as a replacement for a lawyer.

What’s Copyright?

A copyright is the process in place to prevent “stealing” of work.

What does Copyright cover?

Copyrights can only cover tangible things, such as music, a video, an article, but not and idea. Nor can they cover a mere “list” of things, such as a the ingredients to a recipe, but if the recipe is more substantial and includes directions, then it can be copyrighted.

Copyright covers: derivatives produced of your work, distribution, display, and reproduction.

When does copyright begin?

Copyright takes effect at the very beginning – when you develop the material. You do not have to have the Copyright notice up for a copyright to be in place.

How do I place a copyright?

A copyright statement is pretty strict and must follow a certain format. A statement such as “Everything on this website is MINE!” is not a proper copyright statement and holds no legal water. Instead, you need to place a statement like this somewhere on your website, it does not need to be very large:

Copyright © 2011 John Smith

The copyright symbol can be created in HTML with:  

The word ‘Copyright’ is optional, but the copyright symbol is not. The year should list all years that you wish your work to be copyrighted. The year obviously can’t start before the work was created and cannot extend past the current year. There are a few deviations that can be made to this format, however, this is the most standard one.

Where to put the copyright notice?

The best place to put it is on the top-level of the website, for example, the home page. You don’t need to put it on every page, though you can if you like.

Someone stole my stuff!

There are a few ways to go about this. The first way is to kindly contact the person and request they take the work down (I strongly recommend also including a deadline). The second is to go to their webhost and complain, giving concrete evidence of the items in question and the person’s refusal to take it down. Most webhosts take copyright infringement very seriously. The third option is to find a lawyer.

What about contractors?

This becomes very tricky. Ownership of the work should be outlined in the contract that you signed. If it’s not, then it is safe to assume that the contractor is the creator of the work and retains rights to it.

h1

ASP.NET Connecting to an (LDAP) Active Directory Server

October 4, 2011

There are many things that you can do with an Active Directory (AD) server – query users, groups, and so on. It can also be used instead of Windows Authentication, and usually will bypass any username/password logon boxes for non-IE browsers. For my purposes, I need to figure out if user X is in group Y.

Here’s what I have:

        public static Boolean isHealthServices(String username)
        {
            bool isInRole = false;
            String domainname = "something.org";
            String conProperties = "CN=Users,DC=something";
            String domainqueryusername = "username";
            String domainqueryuserpwd = "password";
            String group = "CN=GroupY";
            using (var ctx = new PrincipalContext(ContextType.Domain, domainname, conProperties, domainqueryusername, domainqueryuserpwd))
            {
                using (var grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, group))
                {
                    isInRole = grp != null && grp.GetMembers(true).Any(m => m.SamAccountName ==  username);
                }
            }
            return isInRole;
        }

But, I encounter lots of errors.

The Server Could Not Be Contacted

As it says, it really can’t even find the server. The first thing to do is doublecheck your domainname. Next, check the properties that you are using.

There Is No Such Object On The Server

Your connection properties are wrong. I found that this tool, BeaverTail, is especially useful for figuring out where you are going wrong. You can traverse the LDAP server as ASP.NET would (especially since it is written in C#). The tool is free.

A Referral Was Returned From The Server

Make sure that you prefix the username with the domain. For example “GLaDOS\bob” .

This can also occur if your connection properties aren’t traversing to the correct place. Check the properties that you are using.

A Local Error Has Occurred

This can occur if you used a “/” instead of a “\” in the username. (Note that ASP.NET uses “\” as it’s escape character so “\\” will accomplish this).

An Operations Error Occurred

This one is related to permissions. You’ll want to look into your IIS settings, asp.net user account permissions, and impersonation in your web.config file.

h1

11 Programming Mistakes You Don’t Even Realize You’re Making

September 28, 2011

Disposing Objects Properly

The ‘using’ syntax doesn’t get nearly the kind of exposure it should, and it’s all to easy to not understand which objects need to be disposed of properly, and for which it doesn’t matter. For example, I bet you realize that SQLConnections should always be closed, and disposed of, but what about StringWriter? It too needs proper attention.

using (StringWriter myStringWriter = new StringWriter())
{
	// . . .
}
using (SqlConnection con = new SqlConnection(myConnectionString))
{
	using (SqlCommand cmd = new SqlCommand(stringSQL, con))
	{
		// . . .
	}
}

Filling Your Database With Bad Data

User input. We love it, we hate it, and most of the time, it defies our expectations in one way or another. Here are some ways you probably aren’t properly taking care of your data:

  • proper capitalization of names
  • trimming leading and trailing spaces or zeros
  • verification of birth-dates : leap years, and improbable ages (a user registering who says they are 110 years old? Or, that they are only 2 years old?)
  • data encoding and decoding, especially for HIPA requirements
  • along the lines of multi-line or rich-textboxes, cleaning up HTML where there shouldn’t be any or removing MS Office meta-data from naive users’ copy-paste operations
  • length restrictions both in your code and on your database – so your FirstName field doesn’t take up VARCHAR(MAX) disk space

Shooting Yourself In The Foot With Lack of Documentation (Or Comments)

Simply put, the proper amount of documentation is near impossible to achieve. While we shouldn’t be writing novels in our code, they should quickly jar our memory when we need to revisit them a few years later. Whether it’s specification documents, contracts, or comments, it’s all to easy to fall short.

Slowing Your Own Server Down With Debug Mode

Debugging is great for us developers, but in production servers, it takes up extra processing power.

<compilation debug="true">

Unnecessary Post Back Operations

While intermediate developers are probably aware of the IsPostBack feature, new ones may not be, causing unnecessary operations – which usually involve database calls

Unusual Circumstances Bypassing Your Data Validation

Did you know that sometimes your submit button’s onclick or onclientclick method can be called even though your validators have errors? It is true! Checking Page.IsValid will save heartache and mysterious bad data.

if (! Page.IsValid)
{
// return to the page - the validators will now show their error messages
return;
}

Sluggish Server Responses Via UpdatePanel

Although it seems like magic, ASP.NET AJAX’s UpdatePanel has some necessary flaws, and it’s important to know them. When UpdatePanel updates asynchronously, it performs a postback by sending the data of everything inside it via HTTP. Now, if you have a lot of data inside your UpdatePanel, this update is going to be very slow.

Crashing Your Own Server With Session Data

If you’re storing a lot of stuff in your Session variables, be warned, this can act like a DOS attack on your server (OWASP, more info). Basically, SessionData takes up memory, and with enough users, it begins to act like a memory leak.

Query Variable Injection

Query variables can be useful, but also terrible, as it exposes data to the user for all-too-easy manipulation any dabbler can play with. SQL injection is also something to watch out for, however the fix for this can be as simple as using ASP.NET’s built-in parametrized queries.

Leaving Document, HTML Files Insecure

By default, IIS only applies your security settings (usually in your web.config file) to ASP and ASPX files, leaving any images, HTML, or other document files open for anyone who has the URL. To fix the problem, special settings can be applied to IIS.

Tying Your Database’s Hands Behind Its Back With Lack Of Keys and Indexes

MS SQL Server, and other servers, have out-of-the-box optimizations that make your queries run surprisingly fast. However, they all depend on the query analyzer being able to pick up on ways to speed up the query. Basically, when you don’t use keys or indexes, the query analyzer doesn’t know what to do with your data, and thus can’t really make any optimizations. As a result, it defaults to the most reliable way of doing things, which is consequentially, the slowest.

h1

10 Ways To Make Your Project Fail

September 20, 2011

Not Understanding The Problem

There’s nothing that can hinder your entire application than not understanding the problem or process at hand. And this is nearly guaranteed to happen unless you’ve sit down and done said process yourself by hand. If you don’t understand the problem, then your users aren’t going to be able to understand your application.

It’s Ugly

Aesthetics are important! If your clients don’t like the way the application looks, they already feel they won’t like using it, either.

Poor UI

In my own opinion, the UI is one of the most important aspects of a program. Asking for unnecessary information, not prepopulating data, not telling the user what it is they are doing, textboxes in random places, … ; the list of terrible things to do goes on and on. Only experience, and lots of books and examples, can give you a feel for how to do it right. But the bottom line is: it has to enable the user to be as lazy as possible.

Poor Coding

While there’s a certain stigma that programmers should always write good and clean code, only the experienced ones do. It takes many, many mistakes to finally become ingrained that poor code only leads to more bugs, more headaches, less readability, and slower programming. Refactor and bug hunt as you go along rather than saving it for a proverbial single day when you aren’t too busy.

No Contracts

Clients are well known for putting you in trouble spots, and fast. Scope creep, deadlines, price negotiations, bugs, taxes, … For any contract worth as much as a lawyer consultation, it’s worth it to spend that extra time and money. Especially when there are multiple people working on the project.

Saying Yes To Everything

Even if you have a contract, it’s still all to easy to fall into the pit of wanting to be a people pleaser and saying ‘Yes’ to everything. You absolutely must stick to your guns and the terms of the contract. Make sure you have defined exactly what you will and won’t do in terms of bugs, feature requests, changes, additions, deletions, etc.

Poor Client Communication

It’s extremely important to keep your clients informed on how their project is doing. Whether things are going smoothly, poorly, or you just don’t know, make sure to remain perfectly transparent. Make sure your clients understands exactly what you are doing (to a reasonable level) and where their money is going. This fosters a sense of trust and an overall better project. A good rule of thumb is to respond to any email within 24 hours, even if it’s to say that you need more time to formulate the answer. Consider a live timesheet or bug tracking application so your client can keep tabs at a glance and when they choose.

No Tester

Not having a tester nearly guarantees that bugs will be found. It’s simply insane to demand that a programmer catch all of his own bugs, because after looking at it for X hours, things are going to skirt by unnoticed. Even if you do have a tester, some things may not be caught, but your software will definitely be in better conditions with one.

No Backups

Harddrives can, do, and will fail at the worst possible second. It is simply not acceptable to store all of your project on one medium and expect it to always be grand. Make sure you have backups, whether they are offloaded to a different server, website, cloud storage, or even your flash drive.

You

You yourself have the greatest bearing on your project because you directly influence it. Perhaps you just can’t motivate yourself to start until the night before it is due. Perhaps you didn’t realize that you were in over your head. Perhaps you didn’t give yourself enough time to account for family emergencies. Whatever the problem, you need to be prepared and capable of combating your own weaknesses, whether it is incompetence or burn out.

h1

What To Do When Your Favorite Website Dies?

September 16, 2011

When The Website Is Abandoned?

There is very little you can do here, although sometimes encouraging the author/owner can revive the stagnation. Just knowing that one has a caring reader is often enough to spur on new efforts.

When The Website Is Down?

Before you send a nasty email to the owner about how important your fix is, perhaps you should make sure it’s not just you.

Is It Just You?

First and foremost, figure out if it’s just you with Down For Everyone Or Just Me?. If it’s just you, make sure your internet is working, refresh the page, restart your browser, try clearing cookies and caches. You can also do some tinkering like pinging, tracert, proxies, etc.

The Website Is Down!

Your options become limited. The most obvious is to contact the owner. The less obvious thing to do is figure out why. Check whois records to determine if the domain expired. Check network/site activity charts from third parties to determine how long the outage has lasted. If it’s an outage, chances are that the site will restore itself over time (the webhost is probably at fault here and they work behind the scenes to clear the problem).

There’s An Error That Makes The Website Useless

Your only option here is to try to find a workaround to accomplish what you are trying to do and tell the owner about it.

The Domain Expired

Most webhosts and domain registrars have policies in place never to share account details with anyone except the account holder – this also means that you cannot donate your own money directly to the hosting/domain company.

You can try to gather up any needed materials with The Internet Archive or even Google cached search results pages (click the ‘cached’ to view the cached page instead of visiting the dead website). If you can gather up enough old webpages, you may want to consider mirroring the dead site (creating a new website with the old website’s materials). For example, this is how Bonsai Kittens meme survives on the web, thanks to a generous fan.

Follow

Get every new post delivered to your Inbox.