How to debug ASP.NET MVC bug with database remotely? - c#

I made an ASP.NET Web API project in VS2013 with one controller. The setup uses Entity Framework Code First.
When I run it locally, it works fine. But when I publish it to Azure Web App, calls to the controller will wait for a long time or returns an error An error has occurred.
I removed codes which work with DB and it works again.
The plan has 1GB of storage and I want to use it rather than paying for a separate database service.
How can I debug it to see what happens on the server with the database?
Thanks.

You can set your connection string in Azure control panel which will be used instead of one in your web.config.
You can also turn on error reporting in your web.config file to see if you are getting the 26 - Database not found error (connection timeout).

Related

Modifying web.config while the site is running

Whenever I need to make any changes in development I used to modify the web.config file and restart the app in IIS/Visual studio. This method used to work in production too. Today when I changed the web config file I got the error message
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The configuration file has been changed by another program.
I think that this caused because the application was still running. I know the purpose of an app_offline.htm file and that it can be placed in the root of the application to stop serving out new request. The reason why I cannot do that is because even if I put an app_offline.htm file it does not reflect the changes instantly and this creates chaos.Sometimes when I try from a different network the changes reflects instantly. Could be a cache problem ?
It usually takes take .5 to 1.5 hours for the changes to reflected back for the clients. Sometimes the changes are applied instantly as well. My hosting provider is not that great and I am on shared hosting. So they said that they have 11 load balancing servers and the changes need to get updated on all the servers and could take some time.
To fix the above mentioned error ,I had to personally call the hosting providers and ask them to restart the application pool.
1) Does anyone know what can be done so that I don't have to call up the hosting provider every time?
2) Is the load balancer problem true? I am not sure if it is or they are making it up
PS I do not have Remote IIS access.
Cheers,
Varun

There are no active servers. Background tasks will not be processed

I have a problem which I already looking at it for a few days and still have no solution.
I found this exception in my C# web app log.
[2015-12-03 13:56:06] [ERROR] [] [Error occurred during execution of
'Server Bootstrapper' component. Execution will be retried (attempt
120 of 2147483647) in 00:05:00 seconds.]
[System.Data.SqlClient.SqlException (0x80131904): Login failed for
user "A Network account".
It appears to me that it is using the network account to access the SQL database and because that network account is not granted access to the database, hence login failed and server cannot startup.
However, when I go to the Hangfire dashboard, I can see the recurring jobs, which seems to me that hangfire can access the database with the right account for retrieving the recurring jobs.
Also, in the IIS server, we already set the Identity to "ApplicationPoolIdentity" for the application pools. Hence, we should use the virtual account instead of the network account.
May I know anyone has the similar problem and have the solution. Really appreciate for your help!!
I ran into the same issue using Hangfire with SQL Server and EntityFramework Code First where EntityFramework was responsible for creating the database, so this suggestion is based purely off of that scenario.
If you are using EF Code First, your database isn't created until the context is created and accessed for the first time.
This means that at App Start your database might not exist. Hangfire won't create the database, it only creates the tables in an already existing database.
So what you might be seeing is:
No database exists.
Your app start's up and Hangfire tries to get itself running, the server process throws an error because EF hasn't created the DB.
The web application start finishes since the hangfire service crashing isn't fatal to the application.
Something in your web app calls into EntityFramework.
EF runs and creates the database (likely no hangfire tables at this point)
you access the hangfire dashboard, hangfire is now able to connect, and see the tables don't exist, so it creates them. (now you will see the tables in your db)
The dashboard can now see the database and show you the stats (likely 0 servers running) so it seems like everything is working.
The way I solved it was to make sure that even if the database is empty (not tables), it is at least created. This was hangfire can access it to install it's tables and start, and EF can access it, and create it's schema.
Also, (and this probably isn't it), GlobalConfiguration.Configuration.UseSqlServerStorage() should run first before other Hangfire startup configuration.
Hope that helps!
Steve
You should create background job server instance, see document here
In my case, the server name was too long and there was a SQL error saying it would be truncated. I was only able to see this error after starting it with Just My Code turned off in Visual Studio.
Moral of the story: Use a shorter name for the server and don't append your own unique-per-instance identifiers to it so it can't run into a truncate error. The column is an nvarchar(100).

WCF Service Problems

I'm having trouble setting up my WCF Service to an IIS server. The current setup I have is a WCF service written in C# that accesses an external database (located on a different server, different location than our IIS server) and an ASP.NET web site that consumes the service on our server, and uses it's methods to query, then display some data.
Before I uploaded the Service and website to our server, I tested it using the default setup done by Visual Studio. This test led to promising results, because when I let visual studio host the service (and whatever else it does in order to setup the environment for testing) and consume it with the website, everything went smoothly, and all of my queries went through flawlessly.
I can upload the service fine, consume it fine with the website, but I have problems when my service makes queries to the external database. I get an "underlying provider failed on open" error when an actual query is made. I've tried a few different things and I couldn't find an answer. For legal reasons , I'm not allowed to upload the code, but I think this problem is due to incorrect setup on the server.
Assuming that you're using Entity Framework, that problem almost always indicates that there is an issue establishing a connection to your database. Check your connection string and make sure that the server and instance names are correct, and that the user your service is running under has access to the database. If you're hosting in IIS, this would usually be a service account (e.g. NETWORK SERVICE) or local system account.
The issue ended up being the connection string in the end. On my local machine, the name of the server was resolved with the Hosts file, but the server had nowhere to resolve the name of the server mentioned in the connection string. This was causing the issue. This has been resolved by updating the server hosts file.
I've gotten this error on new installations of SQL Server, and I fixed it by enabling Named Pipes in SQL Server Configuration Manager. Could be the same issue you're having.

Azure web Application CodeFirst Error

I'm creating a Web Application in visual studio for an application.
On localhost, its working smooth, the problem comes when I port it to azure.
http://infolab.azurewebsites.net/api/users/getuserlist
This is the error I get in every single method of the API.
I've created a database in MySQL with MySql Workbench and used entityframework to implement his usage.
Any help?
Thanks
I was having what sounds like the same issue (Can't see the error on the link but my error was in regards to CODEFIRST/Entity issue), couldn't find answers anywhere that would work for me. After a day of trial and head slapping I came across a connection strings setting on Azure that I'd completely forgot I had set up.
Home > App Services > {YOUR APP} > Configuration
At the bottom of the page you'll find Connection Strings . If it is the same problem I was having you'll have at least one in the listings. This setting was overriding my connection strings in code and it was written in a code first format (no meta tag). I simply deleted the entry in Azure then re-published my code. Worked fine after that.
Connection String Section in Azure -> APP -> Configuration
Hope that helps somebody.

Easily switching ConnectionStrings on publish to Azure

I'm currently building an Azure Web Role. I am testing this project against a local database server on localhost. Then, when confident that the project is working, I publish it to Staging on Windows Azure.
However, I also have to remember to change the connection string to point to the live SQL server on SQL Azure before deploying, and then change it back to localhost afterwards.
Is there any nice way to automate this, or perhaps a different process to take to avoid the issue altogether? For example is there a way to have a configuration file for Azure that isn't updated with every deploy?
I ended up just referencing the machine name and whether or not I was using Azure, dynamically switching the ConnectionString I referenced accordingly.

Categories

Resources