skip to Main Content

My ASP.NET Web API project works fine but when I want to run it on a server I can’t pull the data. I’m using an Azure SQL database, I don’t have a problem on the local server.

I can’t figure out why am I getting this error

 System.InvalidOperationException: an error has occurred.   
 The given header was not found

 StackTrace    
 at System.Net.Http.Headers.HttpHeaders.GetValues(String name)    
 at RayTech.API.Security.ApiKeyHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in C:UsersEnesraySourceReposRayTechWebApiRayTech.APISecurityApiKeyHandler.cs:line 23 at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)     
 at System.Web.Http.HttpServer.<SendAsync>d__24.MoveNext()

web.config:

<add name="RayTechDbEntities" 
     connectionString="metadata=res://*/RayTechModel.csdl|res://*/RayTechModel.ssdl|res://*/RayTechModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=*******;initial catalog=RayTechDb;user id=********;password=********;MultipleActiveResultSets=True;App=EntityFramework&quot;"  
     providerName="System.Data.EntityClient" />

Links:

2

Answers


    • connection string of azure SQL database is in the following format :
        Server=tcp:myserver.database.windows.net,1433;Initial Catalog=mydatabase;Persist Security Info=False;User ID=myusername;Password=mypassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
    
    • I think your connection string is not compliant with the above format. you can get your connection directly from portal under connection string tab.

    enter image description here

    Refer this msdoc on sql databse

    Login or Signup to reply.
  1. when using azure database, setting the firewall for the IP of Azure web app is required so that Azure web app can access the database.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search