Server Error in '/' Application when publish to Azure - asp.net-mvc

I have copied the source code from one of my previous NopCommerce websites, copied and renamed the database on Azure and updated the settings.txt file to point to the new database. The only other changes are to the css.
When I run the new site on localhost it works perfect without a hitch but, when i publish from VS to Azure and then browse to the URL i get an error - Server Error in '/' Application. For the life of me I cannot figure this one out and wondering if any one else has experienced this.
I'm using Nop 3.5
My intuition tells me there is something wrong with my connection string, however, why would is work on localhost but not when published?...
Below is the exception details and the stack trace
Thanks in advance for any help
Server Error in '/' Application.
The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.
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.ArgumentException: The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.
Source Error:
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:
Add a "Debug=true" directive at the top of the file that generated the error. Example:
or:
2) Add the following section to the configuration file of your application:
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.
Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.
Stack Trace:
[ArgumentException: The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.]
System.Data.Entity.Utilities.Check.NotEmpty(String value, String parameterName) +61
System.Data.Entity.DbContext..ctor(String nameOrConnectionString) +22
Nop.Web.Framework.<>c__DisplayClass15.<Register>b__9(IComponentContext c) +42
Autofac.<>c__DisplayClass10`1.<Register>b__f(IComponentContext c, IEnumerable`1 p) +10
Autofac.Builder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) +14
Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +32
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
Autofac.Core.Resolving.InstanceLookup.Execute() +132
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +31
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +94
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +185
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
Autofac.Core.Resolving.InstanceLookup.Execute() +132
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +31
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +94
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +185
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
Autofac.Core.Resolving.InstanceLookup.Execute() +132
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +31
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +94
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +185
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
Autofac.Core.Resolving.InstanceLookup.Execute() +132
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +74
Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) +54
Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) +118
Nop.Web.Framework.SettingsSource.<BuildRegistration>b__5(IComponentContext c, IEnumerable`1 p) +35
Autofac.Builder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) +14
Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +32
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
Autofac.Core.Resolving.InstanceLookup.Execute() +132
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +44
[DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. (See inner exception for details.)]
Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +112
Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +108
Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +74
Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) +54
Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) +118
Autofac.ResolutionExtensions.Resolve(IComponentContext context) +46
Nop.Core.Infrastructure.DependencyManagement.ContainerManager.Resolve(String key, ILifetimeScope scope) +89
Nop.Core.Infrastructure.NopEngine.Resolve() +55
FoxNetSoft.Plugin.Misc.RFQ2.UpdateStartUpTask.Execute() +34
Nop.Core.Infrastructure.NopEngine.RunStartupTasks() +477
Nop.Core.Infrastructure.NopEngine.Initialize(NopConfig config) +36
Nop.Core.Infrastructure.EngineContext.Initialize(Boolean forceRecreate) +92
Nop.Web.MvcApplication.Application_Start() +30
[HttpException (0x80004005): An exception was thrown while executing a resolve operation. See the InnerException for details. ---> The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. (See inner exception for details.)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9916673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): An exception was thrown while executing a resolve operation. See the InnerException for details. ---> The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. (See inner exception for details.)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.36215
UPDATE
From the links in my comment I think I need to define the connection string in the below?? from NopObjectContext.cs
namespace Nop.Data
{
/// <summary>
/// Object context
/// </summary>
public class NopObjectContext : DbContext, IDbContext
{
#region Ctor
public NopObjectContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
//((IObjectContextAdapter) this).ObjectContext.ContextOptions.LazyLoadingEnabled = true;
}
}
}

In NopCommerce the connection string is set in a file called Settings.txt which is in your Presnetation\Nop.Web\App_Data folder. However it's not part of the solution so does not get deployed. You can either:
Manually publish that file.
Add the file to your Nop.Web project and deploy it.

Okay so here is what i found.
The statement of the DNS_PROBE_FINISHED_NXDOMAIN error if settings.txt is present in App_Data if 100% correct. The problem is the URL Azure provides http://yourwebsite.azurewebsites.net/ does not work, and its not until the custom domains are hooked up and used to navigate to the website that the site runs as expected.

Related

Using Unity with Windows Azure: An attempt was made to access a socket in a way forbidden by its access permissions

I am currently developing an ASP.NET MVC application that uses Unity for the IoC container. The solution is deployed to Windows Azure using a SQL Azure backend and implments Azure Caching.
After deploying the app to Windows Azure everything seems to work fine. But then after a few requests I get the error "An attempt was made to access a socket in a way forbidden by its access permissions".
For example, if I browse to the site and repeatedly initiate an AJAX POST (e.g. autocomplete input) request it will work fine for the first few requests, but then crash out (by means of displaying a HTTP 500 error in the Chrome Dev Tools console). Then if I try and fresh the page I get the sockets error until the app is restart or the pool is recycled.
Even if I flick between pages I get the same error after a while, i.e. it's not just isolated to the AJAX request. The AJAX request is just the quickest way to replicate the issue.
I'm wondering if the error An error occurred when trying to create a controller of type 'MySite.Web.MVC.Controllers.LocationsController'. Make sure that the controller has a parameterless public constructor.] in the stack trace is a red herring because the ILocationCacheService mapping used by the controller is being resolved by Unity. The AJAX request works for the first few times so it definitely resolves the mapping.
Everything works fine locally, or at least I can't replicate the error.
Stack Trace
Server Error in '/' Application.
An attempt was made to access a socket in a way forbidden by its access permissions
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.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions
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:
[SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions]
System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context) +1847654
System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context) +34
System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state) +271
Microsoft.ApplicationServer.Caching.SocketConnectionFactory.BeginConnect(String host, Int32 port, AsyncCallback callback, Object state, TimeSpan timeout) +469
Microsoft.ApplicationServer.Caching.TcpClientChannelFactory.BeginConnect(String host, Int32 port, AsyncCallback callback, Object state) +119
Microsoft.ApplicationServer.Caching.TcpClientChannel.ConnectAsync() +368
Microsoft.ApplicationServer.Caching.SocketClientChannel.TryGetTcpChannelUntilTimeout(TcpClientChannel clientChannel, ITcpChannel& chnl) +41
Microsoft.ApplicationServer.Caching.SocketClientChannel.Send(EndpointID endpoint, IVelocityRequestPacket packet) +188
Microsoft.ApplicationServer.Caching.SocketClientChannel.Send(EndpointID endpoint, ICreateMessage message) +112
Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.Send(EndpointID endpoint, RequestBody request, Int32 retries) +73
Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.SendMsgAndWait(EndpointID endpt, RequestBody reqMsg, TimeSpan requestTimeout, IRequestTracker& tracker) +428
Microsoft.ApplicationServer.Caching.SocketClientProtocol.SendMessage(EndpointID endPt, RequestBody request) +52
Microsoft.ApplicationServer.Caching.DataCacheFactory.EstablishConnection(IEnumerable`1 servers, RequestBody request, Func`3 sendMessageDelegate, DataCacheReadyRetryPolicy retryPolicy) +253
Microsoft.ApplicationServer.Caching.<>c__DisplayClass5.<Initialize>b__2(RequestBody req) +83
Microsoft.ApplicationServer.Caching.SocketClientProtocol.SendReceive(IVelocityRequestPacket request, Func`2 delegate, EndpointID& destination) +34
Microsoft.ApplicationServer.Caching.SocketClientProtocol.Initialize(IEnumerable`1 servers) +367
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName, CreateNewCacheDelegate cacheCreationDelegate, DataCacheInitializationViaCopyDelegate initializeDelegate) +400
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName) +61
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetDefaultCache() +11
MySite.Services.Cache.Implementations.LocationCacheService..ctor(ILocationService locationService) +64
lambda_method(Closure , IBuilderContext ) +176
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +35
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +10
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +196
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +193
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +113
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +48
lambda_method(Closure , IBuilderContext ) +107
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +35
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +10
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +196
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +193
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +165
[ResolutionFailedException: Resolution of the dependency failed, type = "MySite.Web.MVC.Controllers.LocationsController", name = "(none)".
Exception occurred while: Calling constructor MySite.Services.Cache.Implementations.LocationCacheService(MySite.Services.Interfaces.ILocationService locationService).
Exception is: SocketException - An attempt was made to access a socket in a way forbidden by its access permissions
-----------------------------------------------
At the time of the exception, the container was:
Resolving MySite.Web.MVC.Controllers.LocationsController,(none)
Resolving parameter "locationCacheService" of constructor MySite.Web.MVC.Controllers.LocationsController(MySite.Services.Cache.Interfaces.ILocationCacheService locationCacheService)
Resolving MySite.Services.Cache.Implementations.LocationCacheService,(none) (mapped from MySite.Services.Cache.Interfaces.ILocationCacheService, (none))
Calling constructor MySite.Services.Cache.Implementations.LocationCacheService(MySite.Services.Interfaces.ILocationService locationService)
]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +329
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +15
Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, Type t, ResolverOverride[] overrides) +18
Unity.Mvc4.UnityDependencyResolver.GetService(Type serviceType) +67
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +41
[InvalidOperationException: An error occurred when trying to create a controller of type 'MySite.Web.MVC.Controllers.LocationsController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +77
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +66
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +191
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I managed to resolve this issue using connection pooling for cache with maxconnectionstoserver="1". Here is the web.config setting for the datacacheclient section:
<dataCacheClient name="default" isCompressionEnabled="true" maxConnectionsToServer="1" connectionPool="true" useLegacyProtocol="false">

How to resolve Dynamic LINQ ParseException: "Identifier Expected"

I am getting generic error message System.Linq.Dynamic.ParseException: Identifier expected.
What should I check in order to resolve it? The error isn't very detailed.
I did check the source and the selector params from the ParseLambda method and T-SQL they carry seems valid and execute fine in the SQL Management Studio.
Server Error in '/' Application.
________________________________________
Identifier expected
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.Linq.Dynamic.ParseException: Identifier expected
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:
[ParseException: Identifier expected]
System.Linq.Dynamic.ExpressionParser.ValidateToken(TokenId t, String errorMessage) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1952
System.Linq.Dynamic.ExpressionParser.GetIdentifier() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1941
System.Linq.Dynamic.ExpressionParser.ParseNew() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1038
System.Linq.Dynamic.ExpressionParser.ParseIdentifier() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:966
System.Linq.Dynamic.ExpressionParser.ParsePrimaryStart() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:867
System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:848
System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:844
System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:798
System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:771
System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:702
System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:689
System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:676
System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:662
System.Linq.Dynamic.ExpressionParser.Parse(Type resultType) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:629
System.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:166
System.Linq.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:161
System.Linq.Dynamic.DynamicQueryable.Select(IQueryable source, String selector, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:34
WebUI.Controllers.VoterController.ExportToExcel() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\Controllers\VoterController.cs:2288
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod_callback(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +42
Castle.Proxies.Invocations.ControllerActionInvoker_InvokeActionMethod.InvokeMethodOnTarget() +208
Castle.DynamicProxy.AbstractInvocation.Proceed() +56
Glimpse.Mvc3.Interceptor.InvokeActionMethodInterceptor.Intercept(IInvocation invocation) +408
Castle.DynamicProxy.AbstractInvocation.Proceed() +94
Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +222
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
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) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
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() +8970141
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
ParseException at line 1952:
Call Stack exception source:
OK, I don't know if this is Microsoft bug in the System.Linq.Dynamic library or misuse of SQL column alias names, but in this special case the parser fails:
Select Col1 as First_Name, Col2 as Last_Name, col3 as 2012_P_Customer
From MyTable
The System.Linq.Dynamic parser fails when parsing Col3 as 2012_P_Customer. It did not like the 2012 number as prefix.
When I changed it to "col3 as P_Customer_2012 " it worked fine.
I knew that prefixing SQL column is a bad practice, but I did not know that the same is valid for the column alias.

Deploying MVC3 to a shared host

I am trying to deploy my MVC3 app on a shared host. I've got .Net4 on the shared host and I have worked through the various bin deploy steps cited all over the internet. The problem is that I don't get an error when I try to access the site, I just get a message saying directory browsing is not allowed. I have uploaded the files but its like the server doesn't know what to do when it gets there. I would appreciate any tips anyone has to give regarding this...I need to show a demo today.
Thanks !
Edit:
So I managed to figure out that my host placed my account on a server running IIS6 and therefore cannot process extensionless urls, so I modified my routing table to append a .aspx to the controller name so that IIS can process the request. Now I get this error (which I guess has to do with EF4) when I try to access the url
Attempt by method 'System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(System.Data.Common.DbConnection)' to access method 'System.Data.Common.DbProviderServices.GetProviderFactory(System.Data.Common.DbConnection)' failed.
[MethodAccessException: Attempt by method 'System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(System.Data.Common.DbConnection)' to access method 'System.Data.Common.DbProviderServices.GetProviderFactory(System.Data.Common.DbConnection)' failed.]
System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection) +52
System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +63
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +157
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +51
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +407
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +17
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
WebShop.Controllers.HomeController.Index() in C:\Users\owner\Documents\My Web Sites\WebShop\WebShop\WebShop\Controllers\HomeController.cs:18
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +188
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +267
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +329
System.Web.Mvc.Controller.ExecuteCore() +115
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +94
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8683441
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Anyone know how I can sort this out?
Thanks
It's not enough to move files to the host, you have to tell IIS your files are an application. That's the most common reason for the directory browsing error. Your hoster should have help pages on deploying ASP.NET applications.

EF4 trying to re-create database even though it's already there?

I'm using ASP.NET MVC 3 and have learnt through the MVC Music Store and other sources. I was able to create a database and have it live but the weird thing was about 5 hours after it was live it went down and had the following error and stack trace:
Note: This also seems to be the case whenever I publish the site. I have to go and delete the database manually for it to re create it and then it will work. But now that I'm live I can't do that because data is already being stored in there that I don't want to redo.
File already exists. Try using a different database name. [ File name = C:\HostingSpaces\...\wwwroot\App_Data\Test.sdf ]
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.Data.SqlServerCe.SqlCeException: File already exists. Try using a different database name. [ File name = C:\HostingSpaces\mtnp55\pricexperience.com\wwwroot\App_Data\Test.sdf ]
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:
[SqlCeException (0x80004005): File already exists. Try using a different database name. [ File name = C:\HostingSpaces\...\wwwroot\App_Data\Test.sdf ]]
System.Data.SqlServerCe.SqlCeEngine.ProcessResults(IntPtr pError, Int32 hr) +72
System.Data.SqlServerCe.SqlCeEngine.CreateDatabase() +658
System.Data.SqlServerCe.SqlCeProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 timeOut, StoreItemCollection storeItemCollection) +194
System.Data.Objects.ObjectContext.CreateDatabase() +84
System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext) +8
System.Data.Entity.Database.Create() +76
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +387
System.Data.Entity.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c) +75
System.Data.Entity.Internal.<>c__DisplayClass5.<PerformDatabaseInitialization>b__3() +19
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +72
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +169
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +118
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +190
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +28
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
PriceXperience.Controllers.AppsController.ViewLeaderboards(Int32 gameId) in C:\Users\Public\Documents\Development\...\Controllers\AppsController.cs:42
lambda_method(Closure , ControllerBase , Object[] ) +101
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
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) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
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) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
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() +8841105
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
I've tried many things but still cannot figure out why it does this. I do have a database initialize.
System.Data.Entity.Database.SetInitializer<MobileEntities>(new SampleData());
public class SampleData : CreateDatabaseIfNotExists<MobileEntities>
The code that runs when I try to access the db is the following:
public ActionResult ViewLeaderboards(int gameId)
{
var leaderboards = from u in mobileDB.Scores
where u.GameId == gameId
select u;
return View(leaderboards.OrderByDescending(u => u.Score).ToList());
}
When publishing you need to be sure to REMOVE the Initializer from the Global.asax. The Initializer is only for populating test data, and should not be in use during production. I also remember reading somewhere that setting the Initializer to null might work.
Database.SetInitializer<MyContext>(null);
Or just comment out the line where you call SetInitializer before publishing. I also exclude my Initializer class from the project before publishing.
The default strategy for Code First contexts is an instance of CreateDatabaseIfNotExists.
So it is necessary to include the
Database.SetInitializer<MyContext>(null);
so that the default initializer is not called which might then give an error!
Also, it is necessary to include the generic tag when setting it to null or the compiler will give an error.

Migrating an ASP.Net-MVC Application to a New Server

So basically, I developed this ASP.Net MVC application on a Windows 7 box with Visual Studio 2008. It works well on the local machine, and I was able to host it in IIS no worries. I then decided to upload it onto subversion, and fetch it on a different Windows Server 2008 machine. I downloaded it, had the IIS document root point to my application folder, and started it up.
I can visit the site fine. However, as soon as it needs to do anything with the SQL database I get the following error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
My ConnectionString to the SQL database is as follows:
<add name="UserClaimsConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\UserClaims.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
The error throws a wobble about allowing remote connections, but the database is local! Additionally, when I look at the StackTrace of the error, I see something odd at one portion:
OpenIdProviderMvc.Models.ClaimRepository.ResetAutoSend(String upi) in C:\OpenIdProviderMvc\Models\ClaimRepository.cs:40
The directory which it is referring to happens to be where I had it stored... on the development box! It is stored in a different location on the Windows 2008 server.
Where have I gone wrong in migrating this project?
EDIT:
Here is the full stack trace to provide a bit of additional information.
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4860189
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +376
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4861315
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user) +44
System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() +45
System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() +20
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +57
System.Data.Linq.DataQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +35
OpenIdProviderMvc.Models.ClaimRepository.ResetAutoSend(String upi) in C:\Downloads\DotNetOpenAuth-3.3.1.9337\OpenIdProviderMvc\Models\ClaimRepository.cs:40
OpenIdProviderMvc.Controllers.AccountController.LogOn(String userName, String password, String returnUrl, Boolean resetAttributeRelease) in C:\Downloads\DotNetOpenAuth-3.3.1.9337\OpenIdProviderMvc\Controllers\AccountController.cs:66
lambda_method(ExecutionScope , ControllerBase , Object[] ) +245
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +24
System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +258
System.Web.Mvc.<>c__DisplayClassc.b__9() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
System.Web.Mvc.Controller.ExecuteCore() +123
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
The path in the stack trace probably points to some path on your dev machine because that is what is in the .pdb files (have they been added to subversion?). I don't think this is related to the connection error and you will probably have to sort that out separately.
You need to install SQL Server 2008 Express on the server if it is not already installed. ASP.NET needs sql server express installed to attach the mdf database file in your data directory.
You can download it here

Resources