0

I am having a strange error with publishing my website to Azure. I published it to the service using VS 2010 but then have run into this error in connecting my database to the website. The login page works, as do most of the pages on the site, even those that rely on the very same database. The page with the issue comes up with the following text:

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an  instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   MAO.Controllers.ReviewController.Index() +603
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[]     parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
   System.Web.Mvc.Controller.ExecuteCore() +106
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

The error occurs within the following section of code:

public ActionResult ShortDateResponse(int reviewId, int questionId, string response) {
        if (string.IsNullOrEmpty(response)) {
            var answer = repository.GetAnswerByQuestionId(reviewId, questionId);
            if (answer != null) {
                repository.DeleteAnswerById(answer.Id);
            }
        } else {
            try {
                DateTime date = DateTime.ParseExact(response, "MM/yyyy", CultureInfo.InvariantCulture);
                repository.ShortDateResponse(reviewId, questionId, date);
            } catch (Exception fe) {
                throw new ArgumentException("Date format should be MM/yyyy", fe);
            }
        }
        return Json(new {
            success = true,
            error = "none"
        });
    }

on this line:

DateTime date = DateTime.ParseExact(response, "MM/yyyy", CultureInfo.InvariantCulture);

As such, it seems to me the code is not responsible.

I have tried uploading the database to Azure multiple different ways, and according to the various Microsoft tutorials, and have reviewed others who have presented very similar questions on SO and other places. At this point I am not sure how to move forward, so I'm asking.

Initially, I used SQL Management Studio 2008R's "Extract Data-Tier Application" and "Import Data-Tier Application" to load the schema for the database, then "Export Data" and "Import Data" to load up the data onto the server. I ensured that the commandtimeout variable was sat to 0 for all tables so nothing would get lost along the way, and sure enough, everything showed up on the Azure database. When this presented the aforementioned error, I attempted to use the "Generate scripts" to upload the schema, in case there had been some error with my previous process. I then used Export/Import Data to put the data on the website. I received the same error.

This website does work properly on internal servers, an has been deployed successfully elsewhere, but I'd like to migrate to Azure if possible. Also, I have checked the uploaded website linked to local SQL servers and it has worked properly, so the issue lies in the upload of the SQL database to Azure servers.

I am aware that many people with this error have been able to solve it by editing their connection strings within web.config. I have looked into this, and have manually edited my connection string via Filezilla to the format put forth on various websites, to no avail.

I would really appreciate any insights you have, and let me know if you need more details. Thank you!

4

1 回答 1

0

一种想法是它可能是 SQL Azure 实例上的防火墙规则。在 Windows Azure 管理门户中,转到该 SQL Azure 服务器的“配置”页面。是否设置为“是”以允许 Windows azure 服务?

您还可以发布控制器操作 MAO.Controllers.ReviewController.Index() 的代码,以便我们可以看到发生空引用异常的位置吗?

于 2013-04-17T22:53:24.427 回答