3
votes

I'm trying to submit a workItem to TFS "ONLINE" through a WEB API. It works fine in my local machine but when i upload it to the shared hosting server it's not working.

An error has occurred. Error HRESULT E_FAIL has been returned from a call to a COM component. System.Runtime.InteropServices.COMException at Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.DataStoreNative.UpdateMetadata(IntPtr handle, Object rowset, String dbstamp, UInt32& changes) at Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.Datastore.UpdateMetadata(Object rowset, String dbstamp) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.EndBackendCall(BackendCallData data) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.RefreshCacheInternal(BackendCallData& data) at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.InitializeInternal() at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.Microsoft.TeamFoundation.Client.ITfsTeamProjectCollectionObject.Initialize(TfsTeamProjectCollection teamProjectCollection) at Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.InitializeTeamFoundationObject(String fullName, Object instance) at Microsoft.TeamFoundation.Client.TfsConnection.CreateServiceInstance(Assembly assembly, String fullName) at Microsoft.TeamFoundation.Client.TfsConnection.GetServiceInstance(Type serviceType, Object serviceInstance) at Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.GetServiceInstance(Type serviceType, Object serviceInstance) at Microsoft.TeamFoundation.Client.TfsConnection.GetService(Type serviceType) at Microsoft.TeamFoundation.Client.TfsConnection.GetServiceT at FeedBackService.Models.TFSManager.AddWorkItem(String title, String description, String imagePath) in e:\Industry\InsightSoft\FeedBack\FeedBackService\FeedBackService\Models\TFSManager.cs:line 249 at FeedBackService.Controllers.ValuesController.Get() in e:\Industry\InsightSoft\FeedBack\FeedBackService\FeedBackService\Controllers\ValuesController.cs:line 28 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c_DisplayClass13.b_c(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c_DisplayClass5.b_4() at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)

My code:

public void AddWorkItem(string title,string description,string imagePath)
        {
            string _myUri = "https://testredrock.visualstudio.com/DefaultCollection";

            NetworkCredential netCred = new NetworkCredential(userName, password);
            BasicAuthCredential basicCred = new BasicAuthCredential(netCred);

            TfsClientCredentials credential = new TfsClientCredentials(basicCred);
            credential.AllowInteractive = false;

            string TFSServerPath = "https://testredrock.visualstudio.com/DefaultCollection";



            using (TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(TFSServerPath), credential))
            {
                CatalogNode catalogNode = tfs.CatalogNode;

                ReadOnlyCollection<CatalogNode> tpNodes = catalogNode.QueryChildren(

                                new Guid[] { CatalogResourceTypes.TeamProject },

                                false, CatalogQueryOptions.None);

                WorkItemStore workItemStore = tfs.GetService<WorkItemStore>();
                Project teamProject = workItemStore.Projects[project];
                WorkItemType workItemType = teamProject.WorkItemTypes[workitemType];

                // Create the work item. 
                WorkItem userStory = new WorkItem(workItemType)
                {
                    // The title is the only required field that does not have a default value. 
                    // You must set it, or you cannot save the work item. 
                    Title = title,
                    Description = "",



                };

                userStory.Fields["Repro Steps"].Value = description;

                // Save the new user story. 
                userStory.Save();

            }

        }
1

1 Answers

2
votes

I had the same error, although I was working on an internal TFS. Clearing the files in:

C:\ProgramData\Microsoft Team Foundation\4.0\Cache

where I was connecting to TFS from solved the problem for me.