Have you tried using the SmartObject Event Wizard in the toolbox? From your code example, I believe you could you could use the event to accomplish the same thing with no code. If you do really need to use code, you might try pulling the "SmartObject Server" entry from the string table for the connection string.
The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.