1

Trying to create a prototype application that will post a new Requirement to HPQC 11.

I've managed to get a solid connection but when I attempt to add the blank requirement I get an AccessViolationException.

TDConnectionClass td = HPQC_Connect(); //Open a connection
ReqFactory myReqFactory = (ReqFactory)td.ReqFactory; //Start up the Requirments Factory.
Req myReq = (Req)myReqFactory.AddItem(DBNull.Value); //Create a new blank requirement (AccessViolationException)
myReq.Name = "New Requirement"; //Populate Name
myReq.TypeId = "1"; // Populate Type: 0=Business, 1=Folder, 2=Functional, 3=Group, 4=Testing
myReq.ParentId = 0; // Populate Parent ID
myReq.Post(); // Submit

Any ideas? I'm fairly new to C# and coding in general, so it's probably best to assume I know nothing.

Ian Moriarty
  • 317
  • 1
  • 3
  • 14

2 Answers2

2

After some significant working through the isse the following code works correctly:

private void HPQC_Req_Create_Click()
    {
        TDConnection td = null;
        try
        {
            td = new TDConnection();
            td.InitConnectionEx("server");
            td.Login(HPQCUIDTextbox.Text.ToString(), HPQCPassTextbox.Text.ToString());
            Console.WriteLine(HPQCPassTextbox.Text.ToString());
            td.Connect("DEFAULT", "Test_Automation_Playground");

            bool check = td.LoggedIn;
            if (check == true)
            {
                Console.WriteLine("Connected.");
                HPQCStatus.Text = "Connected.";
            }

            ReqFactory myReqFactory = (ReqFactory)td.ReqFactory;
            Req myReq = (Req)myReqFactory.AddItem(-1); //Error Here
            myReq.Name = "New Requirement 1";
            myReq.TypeId = "1"; // 0=Business, 1=Folder, 2=Functional, 3=group, 4=testing 
            myReq.ParentId = 0;
            myReq.Post();

            Console.WriteLine("Requirement Created.");
            HPQCStatus.Text = "Requirement Created.";

            try
            {
                td.Logout();
                td.Disconnect();
                td = null;
            }
            catch
            { }
        }
        catch (Exception ex)
        {
            Console.WriteLine("[Error] " + ex);
            try
            {
                td.Logout();
                td.Disconnect();
                td = null;
            }
            catch
            { }
        }

This code requires that the Server be patched to QC 11 Patch 9 (Build 11.0.0.7274) in order to work. Previous versions cause errors, most notably the error in the question.

Ian Moriarty
  • 317
  • 1
  • 3
  • 14
  • If you have access to an HP ALM (12 in my case) site, then you can click on the help button on the top right corner / Getting Started with ALM Open Test Architecture Reference / Getting Started. There , look for the CSharp Example and you'll find some code. – JoanComasFdz Aug 10 '15 at 06:56
0

Requirements in ALM are hierarchical, when creating requirement you need to create it under some existing requirement.

What you want to do is get a hold of the root requirement, it's Id should be either 0 or 1, you can check it in ALM UI.

And then get an instance of ReqFactory from a property on that Root requirement. And then add your requirement to that factory.

Also, make sure you are working on STA and not MTA thread.

Alex Shnayder
  • 1,362
  • 1
  • 13
  • 24
  • Sadly, this might be too high level an answer for my limited experience. I get that Reqs are hierarchical, though I'm not clear on how to get the parent requirement. According to the API, I should be creating an empty object, then populating the fields with the relevant information, including the parent ID. However, the error occurs on the creation of the empty object. As for the threads, I'm totally lost there - I've no idea what type or kind of thread I'm working on, nor how to find that. – Ian Moriarty Aug 06 '12 at 15:43
  • Ian - Were you able to successfully add requirements with the above code, or did this prohibit you from posting the new requirements? I am trying to determine if its worth me going down the path as we use QC for requirements management - if I could programatically load test cases from an excel sheet or a custom forms application it would be huge for our team. – tb. Apr 25 '14 at 14:16