Thursday, July 3, 2008

How to get the connection string for Sharepoint Config Database

Sharepoint Config database connection string is persisted in a Registry key , querying the specific key we can get the config database connection string.

Registry key:
HKLM\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Secure\configdb

Code snippet to get the connection string:

RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Secure\configdb");
DSN = (string) key.GetValue("DSN");
SQLServerInstance = new string[]
this.DSN.Split(new char[] { '=', ';' })[1]


Hope this will help some needy SharePoint Dev.

WARNING : Do not make any changes in the registry without taking proper backups

No comments: