Code Prostitute

the sordid details of my career as a code prostitute

Using SQL Alias for failover with Sharepoint (SPS 2007)

with 2 comments

SPS 2007 does not have any support for automatic failover to the mirror server.

Microsoft suggested using a SQL Alias or the following approach:

The approach for failover is

Ø If the SQL server falls over, use the stsadm command RenameServer to change the db server name, then stop & restart IIS & the timer service.

Ø If a single db other than configdb falls over, detach & reattach the db using the UI or via stsadm commands.

Ø If configdb falls over, the admin must use PSConfig.exe’s configdb command, or the renameserver command. If they use the latter, they’ll have to detach & reattach the other db’s on the same server, to move those back to their original sql server location.

The above approach seemed to be pretty complicated so I decided to use the SQL Alias approach and have written a windows service to monitor the things, here is an overview of the process:

* using cliconfg.exe, create an alias on each SharePoint server in the farm with a name of the currently configured SQL Server that SharePoint is pointed to. Set the value of the alias to the same server name. Example, if SharePoint is using server1 as the database server, create an alias called server1 and set the value of the alias to server1.
o the cliconfg.exe creates a registry value called server1 with the name of the alias in the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo

The data for the server1 value will be DBMSSOCN,server1

* My service periodically queries the database_mirroring_witnesses catalog of the witness server to see what the principal server is for the SharePoint_Config database. This object resides in the master database. Once you query this catalog there is a column that has the current principal server information.
* Remotely query the registries of all the SharePoint servers in the farm to see what database server the SQL alias created above is pointing to. If the alias is pointed at a different server than what the witness server thinks is the principal, remotely update the alias’s value in the registry and run IISRESET.exe /noforce.

The account that runs my service needed to have select access to the databse_mirroring_witnesses catalog on the Witness server.

Also, since I am only querying the witness server to see what the principal server is for the SharePoint_Config database, I am assuming that if this database fails over to the mirror, all the databases have failed over and I am redirecting SharePoint via the alias on all SharePoint servers in the farm.

** I took this from a comment on some site for my own permanent reference **

Written by codeprostitute

January 23, 2009 at 10:19 am

Howto install DBD::mysql on Mac – OS X 10.5.5

with one comment

Not used with permission.

Not used with permission.

I ran into this while trying to run a Perl DBI script on a relatively new Mac (OS X 10.5.5, 2.33 GHz Intel Core 2 Duo MB Pro).

The Perl DBI script, since you asked, is something I’m using to read a tab-delimited file line-by-line, look up some data against my mysql server, and write a Ruby on Rails migration file. The migration file is just a bunch of creates based on the data from the text file. It’s a Rube Goldberg concoction for sure but that’s a testament to the versatility of the (Perl | Python | Ruby) DBI. Python’s the fastest, but I cut my teeth on Perl so that’s what I’m using this time.

I digress… when I tried to run the script, it complained about not having the DBD::mysql installed. So, here’s how I installed it on my machine.

You’ll need X Code tools installed and MySQL Server / Client installed before this… I’m assuming you have it working already. Make sure MySQL is running already.

1. open terminal and attempt to install DBD::mysql from CPAN. Type this: (” :; ” is my terminal prompt)


:; sudo perl -MCPAN -e 'install Bundle::DBD::mysql'

This will likely fail because it needs some building config you need, but it will help get us to the point we need to to finish installing it (make sense?).

2. cd to your CPAN folder:

:; cd ~/.cpan/build/DBD-mysql-[version]

3. Next, type this in to configure the build: Note… for me, I installed MySQL using mac ports, so my mysql install is in /opt/local. You should find out where your mysql install is before entering the paths below.

You can find out typing this in your terminal assuming mysql is running:

:; ps aux | grep mysql


:; sudo perl Makefile.PL \
--cflags="-I-I/opt/local/include/mysql5/mysql" \
--libs="-L/opt/local/lib/mysql5/mysql -lmysqlclient -lz -lm -lcrypt -lnsl" \
--mysql_config=/opt/local/bin/mysql_config5

4. Build and install it (you may or may not have to run this first command with a ’sudo’, try without first of course).

:; make
no errors? proceed...

:; sudo make install

Should be golden now. If you ran into any issues, review the steps, look up errors … good luck!

Written by codeprostitute

December 10, 2008 at 4:53 pm

Posted in Uncategorized

Tagged with

How to move a subversion repository to another server

leave a comment »

I’m posting this here mostly for my own reference and for some friends that I know frequent my blog.

[linux]

At the old server command line, enter the following.

svnadmin dump repositoryPath > repository.dumpfile

Compress if you like and transport to the other machine.  (ie. bzip2, then copy with:  scp).

At the new server command line, enter the following.

cd /path/to/new-repository-parent-directory

…decompress if you need to (ie. bunzip2, unzip, tar xvf…)

svnadmin create repository-name

svnadmin load repository-name > repository.dumpfile

Then on your client machine (your local development instance) enter the following.

svn switch --relocate oldurl newurl

That’s it.  For more, RTM.

Written by codeprostitute

September 8, 2008 at 11:08 am

Posted in Uncategorized

Cisco VPN – Error 51: Unable to communicate with the VPN subsystem

with one comment

** update: For Snow Leopard, you basically don’t have to use Cisco VPN (or can’t)… you can use Apple’s built-in VPN in System Preferences… read more about that here. **

Cisco VPN Error 51

Cisco VPN Client (4.8.x, 4.9.x)

Error 51

If you find this annoying alert when trying to start up the VPN client following a reboot, your disk permissions are probably screwed up. You need to repair them using Disk Utility.

  1. Go into your Application - found in your dock (bottom of your Desktop)
  2. Go to Utilities – found inside the Applications folder
  3. Double-click Disk Utility
  4. Select your HD (hard drive) on the left – mine has the default name of “Macintosh HD”
  5. On the main screen on the right, at the bottom, find button: “Repair Disk Permissions” (click it)
  6. When it is done, you can exit out of this (cmd Q)

Reboot and try to open Cisco VPN Client again… hopefully it started working again beautifully.

There is a temporary fix you can do the might be quicker, but it will only last until your next reboot… Open your Terminal (Applications/Utilities) and enter this:

sudo /System/Library/StartupItems/CiscoVPN/CiscoVPN restart

Again, this is only a temporary (but quick) fix.

As always, if you’re not sure what to do or any of this is confusing you should contact your IT department (assuming you have one).

Written by codeprostitute

June 19, 2008 at 2:30 pm

Posted in Uncategorized

New Neighbor Pain In the Arse

leave a comment »

Mockingbird

Northern Mockingbird (Mimus polyglottos)

This little #$!$@# has definitely earned his name. Since he and his mate moved in to the neighbor’s tree directly behind us, he has been chasing everyone off. Squirrels on their usual routes to and from nut trees in the neighborhood have been terrorized by this little bastard. Other birds, usually quite happy to fly about the yards have been run into our back windows. As they fly by, this Mockingbird locks in on them and they have a mid air-strike dog fight until he runs them into various structures… one bird even died. My wife found the poor, over-stuffed bird (apparently not worthy of withstanding the attack) was flown into our back window and then crashed on our lawn. The feathers are still on the glass outside.  In the last two weeks since he moved in, they’ve run 6 birds, that we know of, into our back windows.

So, how the hell do we get rid of this $!@#head? We can’t exactly kill it, since it is the state bird and all… not that we’re normally into killing birds. I forgot to mention that he also has mocked my wife and me while we’re in the backyard tending to our flower bed. I mean, it’s our flower bed, $#!off. He makes repetitive warning noises and the closer you get, they get louder and more frequent. He’s literally tormenting, killing, and annoying every other happily-existing animal in the neighborhood. I’ve gone out to throw a rock or two at him, and while he hasn’t dive bombed me, I’m sure he’s working it up in his little birdhead.

Any ideas for getting him out of our area? Fake owls? Concrete shoes?

Written by codeprostitute

June 16, 2008 at 5:44 pm

Posted in Rants

Tagged with

Transparent PNG in Rails app not working in IE

with one comment

Transparent PNG images fail to be transparent in IE without some help. Bob Osola (bobosola@gmail.com) has concocted a superb solution on his site (http://homepage.ntlworld.com/bobosola) using javascript. He goes into sufficient depth to address the issue on his site.

A colleague implemented this in a site recently and found that it was failing. It was on a Rails site. Any framework (or website) that implements a caching string identifier on a resource the way Rails does will find that this PNG fix fails because of the condition it uses to look for PNG files.

Specifically, an image tag might reference a source this way:

<img src="/images/transparent.png?1188293953" />

This is called cache busting. Essentially, it involves preventing browsers or proxy servers from serving content from their cache, in order to force the browser or proxy server to fetch a fresh copy for each user request. Cache busting is used to provide a more accurate count of the number of requests from users.

The problem with this is Bob’s PNG fix conditionally identifies PNG’s by whether the name of a file (the value of “src”) as ending with “PNG.” The example listed above, obviously does not qualify.

if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

My copy here employs this change:

if (imgName.match(/\.PNG/))

… reg ex matching in the string. Easy, fix… much ado about nothing, but I wanted to document this for my team.

Written by codeprostitute

August 31, 2007 at 7:00 pm

Posted in IE, javascript, png, transparent

Rails Deployment

leave a comment »

Do yourself a favor and use mongrel cluster with Capistrano deployment… what does all the bruhaha mean? A happier life, my online friend.

Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You

Written by codeprostitute

July 18, 2007 at 1:19 am

Ctrl-Alt-Del on OS X MBP?

with one comment

ctrl+alt+del or ctrl alt del… where the heck do you find the ‘del’ key on a macbook pro? No where, actually. There is a ‘delete’ key, but if you’re reading this you probably discovered that it doesn’t mean the same thing (it’s what Windows users call a backspace).

Anyway, if you’re using Parallels, you can select this from the top menu: Actions » Send Keys » Ctrl+Alt+Del

Otherwise (Bootcamp?), if you can find a keyboard to connect (USB), you can hit Del there, and then map your keys so something like F12 will be ‘Del’ using Microsoft’s own remapping keys tool.

Written by codeprostitute

June 9, 2007 at 3:13 pm

Posted in Uncategorized

Trouble with Windows XP (SP2) on Parallels

leave a comment »

Have you tried installing Windows XP on Parallels? I did. No problem until I tried to install other stuff in Windows XP, like SP2. Actually, out of obligations, I had to install .NET and SQL Server, but in order to do that, you have to install SP2 first.

I got all kinds of errors, and some that merely said, “Data is invalid.” That is really helpful, thanks Microsoft. Anyway, after much frustration, I found that there are basically two things that can help this situation.

1. up the RAM – Parallels gives Windows XP 512 MB by default I upped this to 1024

2. install Windows XP with SP2 built in (don’t try to download SP2 later).

In order to do #2 you have to create your own bootable disk that has Windows XP and SP2 mixed in. Paul Thurrott’s SuperSite has a foolproof guide.

Written by codeprostitute

May 12, 2007 at 3:14 am

Posted in OS X, Parallels, Windows

Rails SQL query

with one comment

I needed to know the highest single (integer) value from a table:column. Not having done this before in Rails, my first intuition was to write something that would create a connection with the db, run a SQL string in a query, return the results to a variable, look in the variable if it came back as an array or some other object and get my value.

As always, I was pleasantly surprised to find that I could run a single query and get my value in a very readable, succinct statement:

@total_pages = ActiveRecord::Base.connection.select_value('SELECT MAX(page) FROM questions')

Beautiful.

Written by codeprostitute

April 25, 2007 at 8:22 pm

Posted in Rails, Ruby, SQL