Not able to store data in database

15 Replies
Denis
Denis3mo ago
$details
MODiX
MODiX3mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
clever_cottonmouth
Basically i want to store json data in database which is coming from jira api
FusedQyou
FusedQyou3mo ago
That still doesn't clear it up What happends? An error? Does the code run at all?
clever_cottonmouth
using (var context = _contextResolver()) { List<JiraRelease> fullAPIList = new List<JiraRelease>(); List<Project> projects = context.Projects.ToList(); foreach (Project project in projects) { string _url = $"rest/api/3/project/{project.Key}/version"; var jsonObject = await _jiraClient.GetAsync(_url);

if (jsonObject["values"] != null && jsonObject.HasValues) { List<JiraRelease> release = jsonObject["values"]. Select(x => { JiraRelease data = new JiraRelease(); data.FixVersionID = x.Value<string>("id"); data.ProjectKey = project.Key; data.FixVersion = x.Value<string>("name"); int statusInt = x.Value<string>("released") == "true" ? 1 : 0;
data.Status = statusInt.ToString(); data.ReleaseDate = x.Value<string>("releaseDate"); return data; }).ToList(); here i am iterating project.Key after that i got response from api but i am getting error to much request i don't know how to handle
FusedQyou
FusedQyou3mo ago
So what happens? Does the code run the loop but throw the error after a few iterations? It's important you share details with us because right now it's still guesswork Try calling the code and see how often the loop is called by logging an integer or something
clever_cottonmouth
yes it fail after some looping, I have share completed code above
FusedQyou
FusedQyou3mo ago
Right, but how many iterations is this actually?
FusedQyou
FusedQyou3mo ago
That's not answering my question
clever_cottonmouth
it depends the how much project key we have in our database List<Project> projects = context.Projects.ToList(); foreach (Project project in projects)
FusedQyou
FusedQyou3mo ago
Either way the Jira client throws the error so this is not related to your code but rather Jira telling you to request less often. So perhaps you should add a delay between calls and see if that improves it IDK how many calls can be done since I never used this but try adding Task.Delay in the loop and wait like 5 seconds between calls If that fixes it, perhaps you need a sort of throttle that waits between calls if you get an error like this
clever_cottonmouth
i dont think so jira have time limiting we can hit jira api reapeatedely
FusedQyou
FusedQyou3mo ago
Your code is not the thing that is going to complaina bout "too many requests", it is definitely the call to Jira But if you are certain that's not the case then actually test the code instead of assuming it's not the case For example, set breakpoints and follow the code step-by-step. Or use a try-catch and handle the error so you know where the code threw the exception
clever_cottonmouth
ok i can try that also i will let know once it work