Highlighted
Respected Contributor.
Respected Contributor.
489 views

Robust way to handle SDK connections

Hi All,

We have developed a ASP.net MVC web app which acts a custom UI for HPRM 8.3.

I wanted to check if anyone has any comments on creating a robust way to handling HPRM connection in .net.

I don't know if SDK has inherent properties to check failures and then re-initialize or re-establish connection withoute going completly dark.

In our case, if multiple concurent users access the system or if something goes wrong the code is not able to recover from failure and only option is to reset IIS. 

The following is the coding done for connectivity and interaction

In global.asax.cs

protected void Application_Start()
{
//MVC4 intialization code....

TrimApplication.TrimBinariesLoadPath = ConfigurationManager.AppSettings["DLLPath"];
if (TrimApplication.ServiceType != ServiceTypes.WebService)
{
TrimApplication.SetAsWebService(ConfigurationManager.AppSettings["DLLPath"]);
}
TrimApplication.Initialize();
}

In a regular class (used as a data layer for HPRM)

 

public class HPData
{
public Database hp = null;

public HPData()
{
if (hp== null)
hp= HPConnect();
}

public Database HPConnect()
{
try
{
hp= new Database();
IIdentity id = HttpContext.Current.User.Identity;

hpConnect.WorkgroupServerName = workGroupServerName;
hpConnect.Id = dbInstance;
hpConnect.TrustedUser = id.Name;

hpConnect.ConnectAs(id.Name, "");
hp= HPRMDBConnectDb();
}
catch (Exception ex)
{
throw new Exception(".....", ex);
}
return hp;
}

//Multiple such methods, each using same mechanism to connect to HPRM.....
public List<Record> GetRecordByURI(string recordUri)
{
List<Record> result = new List<Record>();
try
{
using (var hpConnectDb = HPConnect())
{
TrimMainObjectSearch objTrimSearch = new TrimMainObjectSearch(hpConnectDb, BaseObjectTypes.Record);
objTrimSearch.SetSearchString(recordUri);
// some code...

return result;
}
}
catch (Exception ex)
{
throw new Exception(".....", ex);
}
}
}

Can you point out or redirect me to some resources which will make this code a bit more robust and error-proof.

(e.g. having methods to check connectivity before quering, etc.)

0 Likes
1 Reply
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Best to use a pool to store and release the Database object, this is documented here:

https://github.com/HPECM/Community/tree/master/Samples/SDK/CSharp/DatabasePool

Key points are:

  • Database.AllowAccessFromMultipleThreads = true;
  • Manage your own database locks (per user, for example)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.