Меню

How to get Сonnection String Project Server 2010 for PWA Instance

Как получить Connection String for Project Server Instance?

К сожалению, в  Project Server, нет никакой возможность получить имена через PSI.

Поэтому прибегнем к маленькому Hacking’у, получение  Connection String’ов требует использования Reflection.

Вот простой пример:

internal static Dictionary GetDbConnectionString(Guid pwaSiteId){

Dictionary _psDbNames =

new Dictionary();

Type _platformContextType = Type.GetType(

"Microsoft.Office.Project.Server.Base.PlatformContext, " +

"Microsoft.Office.Project.Server, " +

"Version=14.0.0.0, Culture=neutral, " +

"PublicKeyToken=71e9bce111e9429c");

Type _projectSiteType = Type.GetType(

"Microsoft.Office.Project.Server.Administration.ProjectSite, " +

"Microsoft.Office.Project.Server.Administration, " +

"Version=14.0.0.0, Culture=neutral, " +

"PublicKeyToken=71e9bce111e9429c");

Type _projectDatabaseType = Type.GetType(

"Microsoft.Office.Project.Server.Administration.ProjectDatabase, " +

"Microsoft.Office.Project.Server.Administration, " +

"Version=14.0.0.0, Culture=neutral, " +

"PublicKeyToken=71e9bce111e9429c");

MethodInfo _getProjectSiteMethodInfo =

_platformContextType.GetMethod("GetProjectSite", new Type[] { typeof(Guid) });

object _projectSiteObject = _getProjectSiteMethodInfo.Invoke(null, new object[] { pwaSiteId });

PropertyInfo _workingDatabaseProperty = _projectSiteType.GetProperty("WorkingDatabase");

PropertyInfo _publishedDatabaseProperty = _projectSiteType.GetProperty("PublishedDatabase");

PropertyInfo _versionsDatabaseProperty = _projectSiteType.GetProperty("VersionsDatabase");

PropertyInfo _reportingDatabaseProperty = _projectSiteType.GetProperty("ReportingDatabase");

PropertyInfo _dbConnectionStringProperty = _projectDatabaseType.GetProperty("DatabaseConnectionString");

object _workingDatabaseObject = _workingDatabaseProperty.GetValue(_projectSiteObject, null);

object _publishedDatabaseObject = _publishedDatabaseProperty.GetValue(_projectSiteObject, null);

object _versionsDatabaseObject = _versionsDatabaseProperty.GetValue(_projectSiteObject, null);

object _reportingDatabaseObject = _reportingDatabaseProperty.GetValue(_projectSiteObject, null);

SqlConnectionStringBuilder _connectionStringBuilder = new SqlConnectionStringBuilder(

_dbConnectionStringProperty.GetValue(_workingDatabaseObject, null) as string);

_psDbNames.Add("Working", _connectionStringBuilder.ConnectionString);

_connectionStringBuilder = new SqlConnectionStringBuilder(

_dbConnectionStringProperty.GetValue(_publishedDatabaseObject, null) as string);

_psDbNames.Add("Published", _connectionStringBuilder.ConnectionString);

_connectionStringBuilder = new SqlConnectionStringBuilder

(_dbConnectionStringProperty.GetValue(

_versionsDatabaseObject, null) as string);

_psDbNames.Add("Versions", _connectionStringBuilder.ConnectionString);

_connectionStringBuilder = new SqlConnectionStringBuilder(

_dbConnectionStringProperty.GetValue(

_reportingDatabaseObject, null) as string);

_psDbNames.Add("Reporting", _connectionStringBuilder.ConnectionString);

return _psDbNames;

}