Month: July 2013

++i will increment the value of i, and then return the incremented value.

i = 1; j = ++i; (i is 2, j is 2)

i++ will increment the value of i, but return the pre-incremented value.

i = 1; j = i++; (i is 2, j is 1)

For a for loop, either works. ++i seems more common, perhaps because that is what is used in K&R.

In any case, follow the guideline “prefer ++i over i++” and you won’t go wrong.

There’s a couple of comments regarding the efficiency of ++i and i++. In any non-student-project compiler, there will be no performance difference. You can verify this by looking at the generated code, which will be identical.

they are able to hold different data types. For example, I can store numbers and strings in the same array as shown here.

PS C:\> $a = 1,2,3,”four”

PS C:\> $a

1

2

3

Four

If I need to change an element in array, I can index into the array by using the square bracket and the index number. To find the upper boundary, I use the GetUpperBoundmethod, and when I have that value, I can easily find the element I need to modify. This technique is shown here.

PS C:\> $a.GetUpperBound(0)

3

PS C:\> $a[3] = 4

PS C:\> $a

1

2

3

4

The way to add a new element to an existing array is to use the += operator as shown here.

One of Microsoft’s best practices for SharePoint is to create a SQL alias for your SharePoint farm. This can ease the transition from one SQL server to another, required in some instances to scale your farm out, as well as to aid in recovery from some disasters. Luckily this is one of the easiest best practices to implement!

To create a SQL alias, log in to your SharePoint server (note: needs to be completed on ALL of your SharePoint servers).

Open Windows Explorer, and browse to “C:\Windows\System32 folder”. Open the program “CliConfg.exe”.

Select the second tab “Alias” of the SQL Server Client Network Utility, and click “Add”.

In the “Add Network Library Configuration” dialog type in the desired alias for your SQL server. A good standard for this is A-[SharePoint Farm Name]. For example, if your farm name was “Intranet” your alias would be “A-Intranet”. Type the name of the actual SQL server you’re connecting to in the “Server name” field. The alias you create needs to be the same on ALL SharePoint servers in the farm.

Select “OK”, and your alias is created! You can now create a SharePoint farm using the Alias as the database server name. If you ever have to move your databases to a new server, you can change the alias to point to the new server name, and keep SharePoint pointing at the alias!

Note: another best-practice on 64-bit systems, is to configure the alias in “C:\Windows\System32\CliConfg.exe” and “C:\Windows\SysWOW64\CliConfg.exe”. You can then use this alias with both 64-bit and 32-bit processes, and is REQUIRED for Project Server 2007 to work properly with SQL aliases.

Over the next few weeks I’ll be creating a dozen or so virtual machines (VM). To save time I’m trying to script as much of the installation and configuration as possible, and today the portion I wanted to script was the creation of a SQL Alias. I’m sure everyone has read my wonderful blog post onCreating a SQL Alias for SharePoint, but that’s a manual process ?

Enter PowerShell!

I found a few threads that discussed doing this, but none detailed the steps 100 percent. I did a little digging with the SQL Server Client Network Utility and the registry, and came up with the script below. Using this I’m able to create the same alias for both x86 and x64 SQL connections on every machine!