SharePoint 2007 / WSS 3.0 - Fixing the "Unable to Add Selected Web Part" ... "The File is Currently Checked Out" Error

By hagrin - Posted on 17 June 2011

Yesterday, I had to post a YouTube video to our SharePoint WSS 3.0 intranet site. If you're not familiar with embedding a YouTube post into a SharePoint page, your best bet is to use the Content Editor Web Part. However, when I went to add the CEWP today, I was receiving the following error -

Unable to add selected web part(s). Content Editor Web Part: The file is currently checked out or locked for editing by another user.

Huh? Before that, I also noticed that when I was trying to add the CEWP web part to our home page, I was able to see the content, yet no other user was able to see the same content.

If you're struggling with this error, you'r in luck because the fix is simple. Just open up SharePoint Designer, navigate to the page that is giving you the error, right click on the page and select "Undo Check Out". That's it - once you do that, try to add the CEWP and it should work. Hope this helps!

C#.Net - Get Remote Computer Uptime

By hagrin - Posted on 15 June 2011

Recently, at one of my jobs, the company's virtual servers were experiencing random, unnoticed reboots that would occur so quickly that their monitoring software, ManageEngine's OpManager (which does an extremely pitiful job at reporting correct uptimes by the way), wouldn't even send out a down alert. Admins were only being notified when they logged onto the box and actually saw a reboot reason message box.

Therefore, to supplement OpManager, we wanted a script/page that gave an overview of all the servers and their uptimes/last reboot. I came up with the following code which will query on a single machine -

using System.Management;

...

ManagementScope scope = new ManagementScope("\\\\COMPUTERNAME\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
// Display the remote computer information
// http://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx - list of available attributes
Console.WriteLine("Uptime : {0}", m["LastBootUpTime"]);
Console.WriteLine("Computer Name : {0}", m["csname"]);
}
queryCollection.Dispose();
this.Close();

You can easily put the machines you want to query in a database or an array and run this code through a loop to query the uptimes of all your machines in an organization. You can also clean up the formatting of the LastBootUptime to be more readable, but that's up to the developer.

Hope this code snippet helps someone manage their networks.

SQL Reporting Services: Fixing the "No Letter Spacing" When Printing Problem

By hagrin - Posted on 07 June 2011

Seemingly out of nowhere, my users were complaining that while their SQL Reporting Services (SSRS) reports were displaying fine on screen once they printed them the font was all screwed up and possibly stretched horizontally. The font looked stretched and there was no spacing between the letters of a word. It happened on all machines using all printers to all users. It broke in a 3 hour window where no patching, reboots or changes were really made.

Our environment consists of -

  • SQL Server 2008 Standard Edition with SP2 64-bit
  • Windows Server 2008 64-bit
  • SQL Server Reporting Services
  • Virtualized using VMWare

After looking at program settings, print queues, etc., a very random internet search provided me with the starting blocks to how to fix this problem. It seems that the problem occurs when after the SQL Server is rebooted, the first person who logs in (usually via Remote Desktop) logs in with a session in 16:9 aspect ratio (widescreen). Weird right?

To fix this problem, you must do the following in this order -

  • Reboot the SQL Server
  • After the SQL Server has finished rebooting, Remote Desktop into the server using the following command - mstsc /v:SERVERNAME /admin /w:1024 /h:768 (this forces the needed 4:3 aspect ratio)
  • Now, try running your reports.

As a side note, just restarting the services did not fix this problem - a reboot was required. Hopefully, this helps some people and people are able to find this post (it was difficult to title this post to make it as helpful as possible). Good luck!

INNER JOIN on the Same Table

By hagrin - Posted on 04 January 2011

Here's something that always bugged me that I finally was able to figure out today (that in retrospect is so simple I don't understand why I struggled so much with it before).

If you've ever looked at the data stored in a SharePoint 2007 / WSS v3 database, you know that the AllUserData table stores an immense amount of list data. Say you had two lists - a list of Employees and a list of Tasks and in the Tasks list you had a Lookup field using the Employees list. You would have a setup like this to ensure data validation, manage a list of employees in a single location and other data structure reasons. So, how would you write a single, direct SQL query against the AllUserTable to return data in two different lists?

Look at the following query -

SELECT a.tp_ID, a.nvarchar1, a.nvarchar3, a.nvarchar4, a.nvarchar5, a.datetime1, b.nvarchar1, a.ntext3, a.tp_Modified
FROM AllUserData a
INNER JOIN AllUserData b ON a.int2 = b.tp_ID AND b.tp_ListID = '{a234a2a6-dbf2-4abf-b1d4-1544305b9cde}'
WHERE a.tp_ListId = '{4BE243EE-E100-4060-9921-840DEB0F54B0}' and a.tp_IsCurrent = '1' and a.nvarchar4 <> 'Completed'
and a.tp_Modified < '12/1/2010' and a.tp_ContentType = 'Item' and a.tp_DeleteTransactionID = 0x
ORDER BY b.nvarchar1, a.tp_Modified

There's two important aspects in the above query that you need to apply in your own queries. First, notice that there is an INNER JOIN statement that joins AllUserData a and AllUserData b. You effectively name the same table twice and designate it with an alias to differentiate the two lists you are trying to join. Second, notice in the INNER JOIN statement that there is an AND operator that allows you to focus your INNER JOIN on only relevant data inside that table.

Hopefully, this little code snippet helps you in your SharePoint development and SQL query writing.

Cheating

By hagrin - Posted on 18 November 2010

Very rarely do I ever write opinion pieces on this site because I try to keep things informational, but every so often an issue gets brought to my attention and I have to speak out about it. Today on Slashdot, I watched the video of a University of Central Florida professor tell his class that about 1/3 of his students had cheated on his midterm. For those who don't have 15 minutes to spend watching the professor relay the circumstances, here's a brief synopsis -

  • After the exam, some basic statistics showed a bimodal grade distribution as opposed to a bell curve distribution that he had seen in past years of teaching the same material.
  • The test used a question bank based on the texts that the publishers had provided.
  • Someone "anonymously" let the teacher know that this question bank was circulating.
  • Professor states that within 95% certainty he has the names of the people who cheated, but instead of taking action he gives the class a deadline to turn themselves in with no punishment.
  • After the deadline, all data will be turned over to Academic Affairs and then it is out of his hands.
  • Around 200 students have turned themselves in at this point.
  • All students would be required to take a new midterm regardless if they cheated or not and they only have a 51 hour window to do so.

I don't even know where to begin with how screwed up this entire story is. Let's see what logical assumptions we can make from the video to help dissect this story. First, the teacher would be able to take the upper distribution, know from past test results how many students roughly should have scored this highly and come up with a rough estimation of exactly how many students successfully cheated on the exam. This severely shrinks the class into a subset that has a high likelihood of having cheated on the exam. However, this alone is not proof of anything.

Second, the "turn yourself in, no punishment, everyone retakes the test" outcome is a zero punishment outcome to those who cheated. When you watch the video, you can sense the anger/disappointment from the teacher in the situation. Therefore, to give cheaters a zero punishment outcome doesn't seem to correlate to the outrage. Therefore, I think it is reasonable to assume that the university opted for a less controversial outcome and that this may have not been the outcome desired by the professor. Therefore, while definitely only an opinion, I do not think that the professor was solely responsible for the resolution to this problem.

Third, it is unclear as to whether or not the question bank provided an answer key. If it did, then without some anomaly in the answers, there would be very little evidence in the answers given to specific questions unless there was some sort of pattern between test takers. One Slashdot poster stated that the teacher could look for tests where easy questions were answered incorrectly and hard questions were answered correctly as some indication of cheating. However, for numerous reasons, this line of thinking is dangerous to those student whom didn't cheat and any number of plausible explanations could explain this type of performance on a multiple choice exam. The conclusion to be made here is that without some unstated anomaly from the professor, making any inferences based on the answers given on an exam is no real proof of cheating and could be best described as inference. If no anomalies exist, then any conclusions drawn on this information is extremely flawed and dangerous to use.

Fourth, without direct testimony from people involved or a forensics trail (email, file sharing, etc.), the professor is probably left in a situation where he has a very good idea of who cheated, but couldn't say with 100% certainty. This is one of the obvious reasons for the "zero punishment" outcome. While I am sure universities can expel students simply for "suspicion of cheating", disciplining over 200 students would end up being costly to the university in several ways. One wonders if the professor had 100% certainty of who cheated if action would have been taken against such a large number of students.

So Why Do I Care?
This story infuriates me because the only people who get punished in this situation are the students who didn't cheat. Again, as always in life, the nice guy finishes last. This professor may have been forced to make a deal with the university so I don't blame him necessarily, but I do blame the university as a whole for not coming up with at least some form of punishment for suspected cheaters.

I'm also mad at those who didn't cheat on the exam? Huh? Why? Too often in life, I see the nice guy not speak up and get trampled on. Where is the outrage of these students who now have to sacrifice time needed to prepare for other classes to retake a test that they already completed ethically? These students probably put in more time studying than the unethical students did since memorizing a set of test questions is much easier. There is a finite number of hours that these students have to prepare for their other classes, why should they be punished again by possibly not performing as well as the possibly could have if they could have alloted the time to those classes? Where is the student protest protecting their rights as students? Why was a "deal" made behind their backs and without their consultation and why didn't they question this procedure? Speak up for yourselves people otherwise life will continue to trample you.

Finally, is this not more proof that the American education system is flawed? When I was in college, I could recite numerous instances of widespread cheating whether it was teaching assistants in the same fraternity/sorority as students and providing them with inside knowledge or answer sharing on large homework assignments or paying other students to write term papers. For a large number of students, college is only another platform to learn how to take shortcuts in life which is why GPAs should be meaningless when employers hire newly graduated students. The entire system needs changing and more tangible skills need to be formed in college so that employers can more accurately identify who will make good employees.

I hope there is more disclosure about situations like these so that change occurs because it's obvious to me that change is desperately needed in the entire education process.

Newton Stability Performance Racer Review

By hagrin - Posted on 05 September 2010

About 18 months ago, I first started to make a concerted effort to perfect my running form so I could run longer, run faster and stay away from nagging running related injuries. As an average ultrarunner, an above average marathoner and a pretty decent half marathoner, I could tell that a more efficient running form would help me translate my longer races into better results. When I found out about Newton Running Shoes, I was intrigued about using a shoe that was built for speed, yet also promoted proper running technique. I decided that I would purchase the Stability Racer model as my next road/training shoe.

First, let’s start off with some of the basics about the shoe. With a size 9 weighing 8.8 ounces, this shoe is light, but not so light as to offer no protection to the bottom of your feet. The shoe is very airy so if you sweat a lot or live in a really hot climate, these shoes allow your feet to breathe which helps eliminate foot moisture and the potential for blisters. Lastly, as with all Netwon running shoes, the Stability Racer comes with their “Action/Reaction Technology” which helps promote better running form, allows for a minimalistic shoe but still provides shock absorption to prevent foot bruising if you put in long runs and high mileage. For all the above, you’re probably going to pay anywhere from $130-$150 USD for your very own pair.

So, what about my personal experience? For me, the Newton Stability Racer is my favorite road/racing shoe around and I highly recommend it even with its somewhat steep price tag. I found that wearing a thin racing sock works best with these shoes as opposed to a regular white sock since a thinner sock allows your feet to stay cooler. The inside of the shoe is extremely comfortable, the lace holes are positioned well and the shoe is extremely light. I did find that when I first switched to the Stability Racer that my calves were sore after a normal 8+ mile run, but that was more from my gait changing/improving than the actual shoe. After only a few runs in these new shoes, my calves got used to the new form and the soreness went away. As for results, I have run personal bests in all distances while wearing Newtons and I do believe that the shoes themselves are a major component to my running successes.

Newton Stability Racer

What was truly great about the Newton Stability Racer was its incredible durability. I was able to put approximately 2300 miles on this single pair of shoes. You can see from the pictures above that the first part of the shoe to go was the outside walling which may be due more to the fact I have pretty wide feet than a defect in the shoe’s design. In fact, I was still able to run with the shoes in the condition shown in the pictures here, but I decided on a new pair of Newton’s more for aesthetic reasons and to make sure fellow runners didn’t think I was homeless. Even more incredible than the 2300 miles I was able to put on these shoes was the fact that the tread on the bottom still looked to be in great shape – such good shape that if I could fix the sidewall with duct tape (or something more sophisticated), I could probably still be running in these shoes.

Newton Stability Racer Bottom

So, while the Newtons are a higher priced brand, you clearly get your money’s worth as most pairs of shoes won’t hold up for as long and will need to be replaced more frequently. In addition to the value for your money, Newton’s will improve your running form and indirectly prevent running related injuries. I highly recommend Newton’s for the serious runner who wants to take their running to the next level and for the novice who wants to develop good running habits and reduce injury concerns.

How To: Setting Up Database Mirroring on SQL Server 2005

By hagrin - Posted on 22 June 2010

After fixing a SQL Server naming issue, I was ready to continue on with my SQL Server 2005 database mirroring project for my client. The resources for setting up database mirroring are very light across the web so I decided I would help others out by writing out a "how to" guide. First, here are some assumptions that this guide uses which mimics the environment my client had for this project -

  • All of the servers involved are joined to the same domain.
  • You will be using a Principal server, a Mirror server and a Witness.
  • The Principal and the Mirror servers are the same version of SQL Server 2005 (in this case, all Standard Edition with SQL Server SP3).
  • The Witness server can be a version of SQL Express and does not need to be a full-blown version of SQL Server.
  • The database you want to mirror is in Full recovery mode.

Now, your server don't have to be on the same domain as you can use SQL Certificates; however, you'll find that database mirroring is much easier to setup if all the machines are on the same domain. The first step is to make sure that all of the SQL instances are running underneath the same domain account as opposed to the Local Account. The easiest way to accomplish this is to open up SQL Server Configuration Manager on each SQL instance, click on SQL Server 2005 Services, right click the SQL Server option, choose Properties and on the Log On tab choose "This Account" and enter in the credentials of the domain account you created to run your SQL services. When you are finished, click OK and your SQL services will restart.

Next, on your Principal server, you want to perform a Full database backup on the database you want to mirror. To do this, connect to the Principal server in SQL Server Management Studio, right click on the database, choose Tasks -> Backup, make sure the Backup type is set to "Full" and make sure you choose a Destination with a file extension of .bak. On the Options page, select the "Overwrite all existing backup sets" and then click OK to start the backup process. Once the backup is finished, you will want to connect to the Mirror server and restore the backup by right clicking "Databases", selecting "Restore Database", choosing "From device", clicking the browse button to the right, selecting your backup, checking the checkbox for your database and going back to the top and selecting the name of your database in the "To database" dropdown. Once that is completed, select the Options page, check the "Overwrite the existing database" option and then choose the Recovery state option that has "RESTORE WITH NORECOVERY" at the end and click OK to being the restoring process.

Once the full backup restoring process has been completed, you need to go back to your Principal server and perform a Transaction log backup. To complete this, you will use the same steps as the full backup except that for the "Backup type" you will select "Transaction Log" and then in the Destination box you will first remove the current destination and then Add a destination where you use a filename with a .trn file extension. Once the transaction log backup has been completed, connect to your Mirror server and restore the transaction log. To do this, you will right click on your restored database, choose Tasks -> Restore -> Transaction Log, choose "From file or tape", browse to your .trn backup, select the checkbox for your backup and then on the Options page choose the option with "RESTORE WITH NORECOVERY" at the end.

At this point you are now ready to configure your database mirroring. Connect to your Principal server, right click on the database you would like to mirror, select Tasks -> Mirror and select the "Configure Security" button. This will launch a wizard where you have to specify the names of your Principal, Mirror and Witness servers, connect to all of them and when you get to the "Service Accounts" page, simply click Finish and click Start Mirroring once the wizard has completed. At this point you should have successfully created a quorum and your database should be successfully mirrored and synchronized.

Hopefully, this guide will help you make your databases more redundant and help your organization attain a higher level of availability.

Fixing the "SQL Server replication requires the actual server name to make a connection to the server." Error

By hagrin - Posted on 20 June 2010

Recently, I ran into a whole set of problems setting up a client's SQL 2005 database mirroring solution. I had successfully setup database mirroring numerous times and I couldn't figure out why I was having such a hard time with this instance. I loaded up the Database Mirroring Monitor, tried selecting my Principal server in the mirroring solution and I received the following error -

"SQL Server replication requires the actual server name to make a connection to the server. Connections through a server alias, IP address, or any other alternate name are not supported."

I was confident that the name I was entering was in fact the current machine name. I decided to run the following query against the master database on the SQL server in question -

SELECT @@SERVERNAME

To my surprise the name listed didn't match the computer name of the SQL Server! At this point, I realized that this server had a different computer name when SQL was installed and the server had been renamed since then. Fixing this problem isn't a trivial renaming of the SQL instance unfortunately. To fix this issue you need to run the following stored procedures -

sp_dropserver 'old_server_name'
GO
sp_addserver 'current_computer_name', 'local'

At this point, if you re-run the SELECT @@SERVERNAME query, you will get a NULL value for the server name even after a restarting of the SQL Service. Just restart the SQLSERVER service and when you re-run the query the new name will now appear.

phpBB3 Mobile Style / Theme

By hagrin - Posted on 15 June 2010

Update 4/3/2012 - So, it looks like phpBB Mobile's website now HTTP 500s and there are much better options for phpBB3 now. Check out these mobile phpBB themes here.

One of my users pointed out to me while phpBB 3 renders fine on mobile browsers with the default template, there's too much pinching and zooming and the such to read a phpBB forum effectively. Therefore, he wondered if there was a style I could implement with some browser detection so that mobile users would have a better phpBB experience. To my surprise, phpBB 3 has no inherent support for mobile browsers and it doesn't seem as if phpBB 4 has any plans on implementing a mobile style/theme/MOD by default. After a lot of searching and some trial and error, I finally found a working solution and wanted to write out that post here so people could follow.

I found phpBB Mobile which was only just recently developed (good timing) less than a month ago. It is a MOD for phpBB that allows for user agent detection so that if one of your normal users browses from their mobile phone, their browser's user agent is detected and a mobile style is used to display your forum. While there is some documentation and a forum dedicated to this MOD, I wanted to add some notes to their documentation.

  1. Download the phpBB Mobile MOD.
  2. Extract the archive locally before uploading to your server for easier manipulation.
  3. Inside the archive open /phpbb_mobile_(version)/install_phpbb_mobile.xml in a browser so that you can read the instructions.
  4. The first "step" you are presented with is a SQL CREATE TABLE command to create the phpbb_mobile table. Note, if you used a different table prefix for your phpBB 3 install, you need to change the table name in this SQL query (for instance, I used phpbb3_*). Run this SQL command on your database server.
  5. The next section is a "File Copy". Copy the files from your extracted archive in the /phpbb_mobile_(version)/root/ folder to the root section of your forum installation on the web server.
  6. The next section is called "Edits". Download the /includes/constants.php and /includes/session.php files from your web server and make the necessary edits locally and then re-upload back to your web server.
  7. You will be at the "DIY Instructions" section. Log into your Admin Control Panel, Click on the System tab, click on "Administration Control Panel" link on the left side vertical menu, click on Styles, click on Style management, click on Styles, and then in the drop down to the right select phpBB Mobile and click Add module.
  8. You should now click "Enable" to enable the module.

At this point, the MOD is installed, but still doesn't do anything "useful" for your mobile users. You still need to install your mobile styles and then create the browser rules and associate them with your mobile styles. You might be wondering if anyone has developed any good mobile styles. The best one I found was an iPhone style also made by phpBB Mobile.

  1. If you need to install a new mobile theme at this point, you must go back to the System -> Admin CP -> Styles -> Style management -> Styles page and Delete the phpBB Mobile MOD. Why? Because, if you go to the Styles tab when this MOD is installed (doesn't matter if Disabled or Enabled), you can't properly install new styles/themes. After this is done, install your mobile style as normal. After you are done installing the style, re-add/re-enable the phpBB Mobile MOD.
  2. At this point, you need to know what your mobile style's Style ID is. If you go to your database, browse the data in the phpbb_styles table (replace phpbb with whatever prefix you used) and you'll want to take note of the ID for your mobile style.
  3. In the Admin CP, click on the Styles tab. You will now notice that phpBB Mobile options are displayed right there on the Styles page. Here, you will add the rules for which style is shown for which browser. The way the rules work is that the "Browser" box should include some unique text string found in a specific browser's User Agent and then the ID for the style you want should go into Style box. So, for instance I added the following - "Android", "iPhone", "webOS" all pointing to style "5" which is my mobile style.

That's all you need to do! Now, obviously, with every upgrade you make to the core phpBB installation, you will have to make sure that this MOD doesn't break. Good luck.

How To: Fix Visual Studio 2008 Design View Hang / Not Working

By hagrin - Posted on 31 May 2010

Recently, I had to do some home .Net development (I mainly do .Net work only at ... work), but when I had some Internet issues and had to work offline, I loaded up my copy of Visual Studio 2008. I opened up my web project and everything seemed to be working fine until I tried to switch to design view on any page or control. Once I tried going to Design View, Visual Studio would stop responding and only a forced quit would close the application. Here's the environmental settings I was working with -

  • Windows Vista Ultimate 64-bit Edition
  • Visual Studio 2008 Service Pack 1
  • Microsoft Office 2010 64-bit

Nothing out of the ordinary as you could see. Obviously, whenever I run into a problem like this, I load up a search engine and search for a solution and found quite a few complaints about this problem. However, after reading the "de facto" solution post from Microsoft, I felt as if I needed to more accurately spell out how to fix this problem since I only found the correct solution after reading through several posts.

  1. Close Visual Studio.
  2. Open up your Control Panel.
  3. Go to your installed Programs and Features.
  4. Look for an entry called Microsoft Visual Studio Web Authoring Component.
  5. Right click on this entry.
  6. Choose Change.
  7. Select the option to Repair.
  8. Re-open Visual Studio and try using design view in your web application.

Obviously, if you don't have this program, you need to install it. Fixing this problem, for me, was really that simple while other posts talked about editing your registry key for Office LastProduct, making sure you had Visual Studio SP1 installed, etc. However, I found that this was the easiest solution that worked for me.