Setting connection string throws a null reference error

The last line of the code is setting the global variable. It is the line that creates the error. The odd thing is that the error only occurs if the reg key is not set yet. If the key is set everything works fine. The global variable is create like this.