Friday, October 25, 2013

Personal Version Control on the cheap (FREE!)

I've always been a fan of version control for my own documents. I can't even begin to tell you how many times I have edited and saved something (code, word documents, really anything) then went back to look for something that I in my infinite wisdom decided to delete because "it would never be needed". Well guess what? I was wrong.

Recently, I've been working much more on scripts mainly TSQL but also find myself building support documents, random documentation, spreadsheets for automation, etc...basically things that change periodically and that I would like to keep previous versions just in case :)

There are all kinds of version control software but I've been a fan of Tortoise SVN in the past and still am. It integrates well with Windows, yes I'm a Windows user; version control isn't only for Linux. TortoiseSVN is actually an Apache Subversion client. While this implies you need a server and really could have one running Subversion, you can also utilize Tortoise SVN to create a local Subversion repository. Note: This means if you care about your repository you will need to back it up.

Here are the steps to create yourself a local version controlled folder:

1. Download and Install the latest version of TortoiseSVN; this will be a next --> next --> Finish type install.

2. Create a new folder that you would like to be the root of your repository. For our example we'll call it C:\SVNRepository.

3. Right Click the folder you created (C:\SVNRepository), you should see a TortoiseSVN menu. Mouseover that menu and you will have numerous options. Choose "Create Repository Here"

4. You will receive a window to confirm. Here you could create the default folder structure of trunk/branch/tags. But I don't and unless you are well versed in using these different constructs I think it just becomes confusing. So, I recommend hitting Ok at this point or go read up on the trunk/branch/tags construct and see if it is something you'd like to try out. This isn't a life or death decision, these are basically just folders and if you end up not liking them well just delete them.

5. Assuming you eventually hit Ok, your folder will now have a different icon that is good. Create a folder in Windows that will serve as your working directory. For our example we'll call it C:\WorkingDirectory.

6. Right Click on C:\WorkingDirectory --> Left Click "SVN Checkout..."

7. You should now have a "Checkout" window open. For "URL of repository:" enter "file:///C:/SVNRepository". The "Checkout directory" should already be set to C:\WorkingDirectory. Click Ok.

8. Double click C:\WorkingDirectory, you now have an empty folder. You can create folders and files in here as you wish. Create something, anything for now.

9. So you've created something in step 8 and your folder is no longer empty. But it is not saved to the repository yet. Right click on C:\WorkingDirectory --> Left click "SVN Commit"

10. You will now have a "Commit" window. It will show you all the changes you have made and a comment box, you should only see new things that say non-versioned at this point and you can add a comment as appropriate. Click the check boxes next to the items you want to save to the repository and click ok. Click Ok again.

11. If you haven't already done so create a document or copy one over, make sure to commit changes as in step 9. You can also right click on a specific file and commit it rather than the entire structure. Modify this file a few times and commit so that we have some changes to revert or compare.

12. Now you should have one file that has multiple revisions, first make sure you left click the file --> then right click on this file --> Mouseover TortoiseSVN --> Left Click "Show Log".

13. You will now have a "Log Messages" window open and you can click on each version of your file. Right clicking any of these versions gives you a plethora of choices including comparing to current version, comparing to a previous version, reverting, saving off a revision as something else, etc...play around and see what you can do.

This is by no means an extensive tutorial on using TortoiseSVN or Apache Subversion but rather a quick and dirty setup guide and just enough to get you going and playing. There are other features you could use such as add (if you have a new file or folder that you create in the structure) this has the advantage of showing you that you have a new file that now doesn't match the repository without committing. You can also import files/folders from an existing location. There are tons of things you can do but you can read more about that at the Apache Subversion Documentation and TortoiseSVN Support websites. You may even find you want or need to setup an Apache Subversion server if you want to use it for more than your personal repository.

Thursday, October 24, 2013

Has Rundll32 run away with your CPU?

So, the truth is you will probably get a call about application slowness and you will see rundll32.exe is taking up all the CPU. You will then proceed to call your server team and tell them to fix it. They will likely tell you that your application is causing it and that rundll32 could be any of a number of things. You will probably yell at them insisting that rundll32 is not part of your application. Luckily I've been a server guy and an application guy so I figured that out myself. But be warned this conversation has and will happen many times.

Easiest thing to start off with is simply trying to figure out what in the world rundll32.exe is actually attempting to do. There are probably many ways to find this but I simply opened up task manager --> clicked on the process tab --> went to the View menu --> Select Columns --> Check the box next to Command Line --> Click Ok.

You will now have an extra column for each process. Find your rundll32.exe process and look at the Command Line column. Hopefully you will see something you recognize but you may find something obscure that requires lots of research...your mileage may vary.

Back to my problem, here is what I found:

rundll32 C:\Windows\system32\spool\DRIVERS\x64\3\hpmsn130.dll,MonitorPrintJobStatus /pjob=31 /pname"printer-c"

That very quickly stood out as a printer related issue because of the spool directory, printer name which wasn't printer-c but changed for this example, MonitorPrintJobStatus, and well those dang hp dlls.

So for a while I cursed printers and HP unified print drivers but realized that wasn't going to fix my problem. I changed the print processor to winprint from the HP specific print processor but that didn't result in a fix.

I proceeded to poke around the printer properties and ran across and option called "Printer Status Notification:" which was the cause of the CPU hogging. I disabled this feature and all was good.

So I went back to cursing HP unified print drivers! But I will save that for another day (we'll call that day never)...I don't like printers.

Wednesday, October 23, 2013

TSQL to find database size

Earlier today I had the need to calculate both the size of my SQL database files as well as the amount of used space in the aforementioned database files. While I was at it I added a percent used column. I found lots of posts out there some horribly complicated and some way too simple and not providing enough detail.

The FILEPROPERTY (http://technet.microsoft.com/en-us/library/ms188401.aspx) was the key here and what I used to simply calculate the amount of space used within the database files.

Also make sure you replace the "<your_database_name_here>" at the beginning of the query or make sure you have the appropriate database selected in SSMS.