Avatar of Philippe Renaud
Philippe Renaud
Flag for Canada asked on

Problem with my API

Hello EE,


I have a problem with my APIs.

the API site opens up well, Its with Swagger UI and I see everything. when I select my GET customer (by the way SQL table is empty) and I click "Try it out" and "Execute"


I see error this error below. Those is just mean there is no customer in my table or its another problem ?


by the way, all the apis (get, put, post etc) were all created with ASP.NET Core API. 


500UndocumentedError: Internal Server Error
 content-length: 0  date: Thu,17 Feb 2022 19:33:42 GMT  server: Microsoft-IIS/10.0  x-powered-by: ASP.NET 

Open in new window

ASP.NET* Forms APIC#* ASP.NET Core

Avatar of undefined
Last Comment
Philippe Renaud

8/22/2022 - Mon
Kimputer

Unclear for now. Options:

- inside the GET code, add more debugging (logging to file for instance, see if the database query returned an error, or just OK but no data).
- just fill the database with a handful of customer.

Either way, try to gather more info.
Philippe Renaud

ASKER
Well ok but, let me rephrase differently to you then  :

Should an API "GET" with an empty table after doing "try it" and "execute" shoul return an error or it should be a success but having nothing as result ?
Kimputer

There are too many variables (MS's ASP code, your code, IIS server), even in a perfect solution, to tell you if it was the correct result or not.
In a programming paradise or heaven, obviously the answer would be "success but nothing as result", but we're not living in a fantasy world.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Chinmay Patel

If it was working fine it will give an empty result. There are other ways to test your API. Swagger is good but when configured incorrectly or when you are new to this entire setup, it may throw you off.

Scaffolded code is generally not a problem. Try setting a break point in your get method which you are trying to call using Swagger and see if the breakpoint gets a hit or not. If it does not, we may have to look in the configuration of your app. If it does then step through your code to see where exactly it is failing.
Philippe Renaud

ASKER
ok guys update:  it works very well from VS2022 "locally" i get my results from the GET.
but from the Publish "Azure" i have the 500 error.
Chinmay Patel

Where have you published on Azure? AppService or VM?
How did you publish to Azure? - Using Visual Studio? What do you get in the error logs or ApplicationInsights.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Philippe Renaud

ASKER
I publish in my VS2022 ASP.NET Core API Solution. I right lick on my project, hit "Publish" I have connection to my Azure subscription and database. when it finishes, it opens automatically browser to my API URL and I see all the API (no error so far), until I click "try it out" and execute i get that Error 500

I have never used ApplicationInsights, not sure how to get there
Philippe Renaud

ASKER
Wait i found the insights, its enabled now. I see this (see picture)

and I was able to find this :

Cannot open server 'xxxxx' requested by the login. Client with IP address 'xxxxxxxx' is not allowed to access the server.  To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range.  It may take up to five minutes for this change to take effect.

does that mean its the permissions on tables?
err500.jpg
ASKER CERTIFIED SOLUTION
Chinmay Patel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Philippe Renaud

ASKER
it didnt work after adding IP but it did work after putting YES to "Allow Azure services and resources to access this server"

im still learning azure but, was it normal to put Yes to that ?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Philippe Renaud

ASKER
Chinmay Patel

it didnt work after adding IP but it did work after putting YES to "Allow Azure services and resources to access this server"

It should have. Basically, Azure SQL does not allow (not even the Admins to access the DB initially. Basically, they want user to configure security on need to basis rather than allowing blanket access.
im still learning azure but, was it normal to put Yes to that ?
Absolutely Yes.

In PROD scenario, if you want to have better control you can explicitly add each Azure Resource that can access your Azure SQL.
Philippe Renaud

ASKER
thanks alot
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Philippe Renaud

ASKER