Using Integers as Boolean Flags

Something I find handy while programming is being able to use the bits in an integer-type variable as boolean flags. What I mean by that is, let’s say you have an INT that is 4 bytes in size. Each byte consists of 8 bits so this INT contains 32 bits in total (4 bytes * 8 bits in a byte). If we have a program that has 32 different boolean variables, wouldn’t it be more effective to store all of them in a single integer variable? This would especially be helpful when you want to keep your networking packets small. 32 booleans in 4 bytes instead of 32 bytes! Ultimately, it’s up to you to decide how to use it; I’m just here to show you how.

Read the rest of this entry »

Fix: Cannot Generate SSPI Context

I was recently working on an ASP.Net project and was receiving this error on attempting to .Open() my SQL Server database connection:
System.Data.SqlClient.SqlException: Cannot generate SSPI context.

As you may have noticed, the connection uses SSPI (i.e. Windows login authentication) to connect to SQL Server. I thought this was a bit strange and tried restarting the project (it was running in debug mode). That didn’t help.

Fortunately, I remembered that my Windows password was set to expire today. It had expired while I was logged in, and so, was preventing me from being able to authenticate my login with SQL Server.

So, if you’re receiving this error, try updating your password if it may have expired.

Latest Posts

Post Calendar

April 2023