multiple active result set(MARS) on Appharbor how to enable? - c#

this is my first question at stackoverflow, so bear with me.
In my local project I use ASP.NET MVC 3 and Entity Framework 4.3 with SQL Express.
in my connection string i have MARS set to true;
but when i am deploying my project on to Appharbor, Appharbor injects its own connection string,
where MARS is not set in the connectionstring. So i get this:
There is already an open DataReader associated with this Command which must be closed first.
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.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
So far best solution i have seen on this: http://support.appharbor.com/kb/add-ons/using-sequelizer
where they have this code:
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var connectionString = configuration.ConnectionStrings.ConnectionStrings["ConnectionstringAlias"].ConnectionString;
if (!connectionString.Contains("MultipleActiveResultSets=True;"))
{
connectionString += "MultipleActiveResultSets=True;";
}
configuration.ConnectionStrings.ConnectionStrings["ConnectionstringAlias"].ConnectionString = connectionString;
configuration.Save();
I can not figure out where to place this, have tried to put it in global under
Aplication_Start() method
But that gives me this error:
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:
Line 50:
Line 51: var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
Line 52: var connectionString = configuration.ConnectionStrings.ConnectionStrings["ConnectionstringAlias"].ConnectionString;
Line 53: if (!connectionString.Contains("MultipleActiveResultSets=True;"))
Line 54: {
Source File: C:\Users\William\Documents\Visual Studio 2010\Projects\xxx\xxx\Global.asax.cs Line: 52
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Educationexpander.MvcApplication.Application_Start() in C:\Users\William\Documents\Visual Studio 2010\Projects\xxx\xxx\Global.asax.cs:52
Is there anyone out there with a solution to this problem ?

Update: Multiple Active Result Sets (MARS) can now be enabled for the injected connection string by using the Sequelizer admin panel. This is the recommended approach since the web.config no longer needs to be modified, which causes an AppDomain reload during startup
Answer is in the above comments, this is just to formalise.
You need to use the correct ConnectionstringAlias (thanks #chris-sainty) and you have to enable file system writes in application settings for the updated configuration to be written to disk.

Related

Configuration Error on Updating Web.config

I would like to update the web.config file by C# in windows container.
The following is a function of updating web.config in C#
private void UpdateWebConfigFile()
{
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var section = (System.Configuration.ConnectionStringsSection)configuration.GetSection("connectionStrings");
var defaultConnection = section.ConnectionStrings["DefaultConnection"].ConnectionString;
section.ConnectionStrings["DefaultConnection"].ConnectionString = Environment.ExpandEnvironmentVariables(defaultConnection);
configuration.Save();
}
but an error occurred in configuration.Save(); that I get the result as following
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: An error occurred loading a configuration file: Access to the path 'C:\inetpub\wwwroot\tynfsgbl.tmp' is denied.
Source Error:
An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Source File: C:\inetpub\wwwroot\web.config Line: 0
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3535.0
My question is How to update Web.config in the application of Windows Container?
Thank you!
Containers are by design intended to be immutable, and as such, the default user is set to a non-admin account which will not have permissions to modify the IIS directoy.
While you can modify the runtime user to be an admin, this would present another issue due to the way that IIS inside a container is montiored. Changing the web.config would cause IIS to reset the pool, which docker would treat as a process crash and stop the container.
Either you should modify the web.config as part of the container build, or you should use environment variables directly rather than trying to write them into the web.config when the container is running.

The application is in break mode after adding an appsettings section

I get the following error message when I try to start my console application:
The application is in break mode
Your app has entered a break state, but no code is currently executing
that is supported by the selected debug engine (e.g. only native
runtime code is executing).
I have put a break point directly at the Main method and the code never gets there.
The only thing I have added is the following values to App.config:
<appSettings>
<add key="QueueItemsToGet" value="25" />
</appSettings>
If I check the exception in Output -> Debug or Diagnostics Tools I can only see this error:
Exception thrown: 'System.TypeInitializationException' in NLog.dll
An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.
The type initializer for 'MyApp.Program' threw an exception.
However if I remove the <appSettings> section everything works, including Nlog.
I should have looked twice, it seems this error can occur if you add sections twice. In my case it was two definitions of appSettings since further down in the config the area was already added. I hope this can help someone else who makes the same mistake.
It was happening to me when I got an error on a static field initialization, for example, if you have a static Uri variable that is initialized with an invalid Uri (an empty string, in my case)

OWIN app on new (SDK) csproj format

While converting an OWIN app to the new csproj format I hit a few issues. The first issue had to do with the changed output directory (since it now includes the runtime in the path). This threw the following error:
Could not load file or assembly 'Microsoft.Owin.Host.SystemWeb' or one of its dependencies. The system cannot find the file specified.
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.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Owin.Host.SystemWeb' or one of its dependencies. The system cannot find the file specified.
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.
I was able to fix this by setting the path in the Web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin/net461" />
</assemblyBinding>
</runtime>
After that I am now confronted with this issue:
The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'ClientWebAPI.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
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.EntryPointNotFoundException: The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'ClientWebAPI.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
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.
I have declared the entry point using the assembly attribute:
[assembly: OwinStartup(typeof(API.Startup))]
namespace API
{
public class Startup
{ /*...*/ }
}
The "Sdk" style csproj, sometimes called the VS2017 project format, does not yet support ASP.NET 4 projects. See the following issues:
https://github.com/dotnet/sdk/issues/491 (1)
https://github.com/dotnet/project-system/issues/2670 (2)
There are two layers of issues here: (1) MSBuild and (2) Visual Studio. If you understand how targets and imports work well enough, you could workaround (1) and make the Sdk style csproj work for an Owin project.
The more difficult part is (2) - Visual Studio. When switching to the Sdk style project, under the hood, VS is switching to an entirely new implementation of the project system, the one that is open sourced in https://github.com/dotnet/project-system. This project system does not yet fully support ASP.NET 4 projects.
You can workaround (2) by using Microsoft.Owin.SelfHost instead of using Microsoft.Owin.Host.SystemWeb. To make using Microsoft.Owin.Host.SystemWeb work, VS needs to know how to generate web.config and applicationhost.config file for IIS Express, how to launch the IIS Express site, and attach to process once launched. Much of that is not ported to the new project system, and I'm not sure if it will be. The new project system was designed to work with ASP.NET Core which uses a very different method for launching and configuring IIS Express.

MixERP database configuration error

I have cloned the project from github and followed instructions from the MixERP documentation. Built the project in visual studio successfully, installed PostgreSQL version 9.6.
When I ran the project it gave me error
relation config.mixerp not exist
We are using VS2015, PgAdmin4.
ERROR: 42P01: relation "config.mixerp" does not exist
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: Npgsql.NpgsqlException: ERROR: 42P01: relation "config.mixerp" does not exist
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.
I was running the same version of VS and pgAdmin. I noticed that running the db scripts does not create any tables or views in the database. My suspicion is that mixerp is not completely compatible with PostgreSQL 9.6 as yet. Looking at the DbServer.config, PostgreSQL 9.4 was used during development.
A downgrade of PostgreSQL to v9.4 will resolve the issue you are experiencing. I suggest completely uninstalling PostgreSQL 9.6 and installing PostgreSQL 9.4 instead and thereafter follow the setup document again.

Error: Unable to generate a temporary class (result=1) ... When Invoking Methods on a Web Service

Error: Unable to generate a temporary class (result=1) ... When Invoking Methods on a Web Service. I am using VS 2008 C# ASP.NET 3.5. I am invoking a remote webservice to my application.
Server Error in '/' Application.
Server was unable to process request. ---> Unable to generate a temporary class (result=1).
error CS2001: Source file 'C:\WINDOWS\TEMP\6sbkwt2d.0.cs' could not be found
error CS2008: No inputs specified
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.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Unable to generate a temporary class (result=1).
error CS2001: Source file 'C:\WINDOWS\TEMP\6sbkwt2d.0.cs' could not be found
error CS2008: No inputs specified
Source Error:
Line 775: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/CheckLogin", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 776: public System.Data.DataSet CheckLogin(string uname, string pswd) {
Line 777: object[] results = this.Invoke("CheckLogin", new object[] {
Line 778: uname,
Line 779: pswd});
Source File: c:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\14127ae4\96323535\App_WebReferences.u9ldrmk1.0.cs Line: 777
First, credit where credit is due. The OP solved this problem and answers it in the comments section of the question. However, I understand that many people come to StackOverflow and will read through the question, and not look at the comments. Therefore, I'm relaying the above answer here. Be sure to up-vote the question if this is useful.
This problem occurs because the account that is associated with your web service's application pool in IIS does not have read/write permission to the C:\Windows\Temp folder. I have no clue why the account needs access to this folder, but it does. From my casual observation it looks like it just writes an empty file with a random name to the Temp folder.
To solve this problem browse to the C:\Windows folder, and right-click on the Temp folder. Select Properties, and on the Security tab add the account associated with your web services application pool. Hit the OK button, go to IIS and recycle your application pool. This should fix your web service request.
It is worth noting that the circumstances around this error can be a bit deceptive. I've ran into this problem a couple times over 5 years. (I've forgotten about it each time.) The reason why it's not so noticeable is because you can publish a web service, successfully browse to the associated asmx page and see the outline of your web service methods. Furthermore, your Visual Studio project can add a reference to the Web Service and Visual Studio will auto-generate all associated classes for the web service in your VS project.
This gives the impression that everything is working properly until you make your first request to execute a method on the web service. The web service will fail when it begins executing code because it wants access to the temp directory.
Further information regarding this bug can be found at the acknowledged bug report at Microsoft.com.
That happens when your web site doesn't work with Application Pool "DefaultAppPool" and you chose its own pool.
In that case you need to add an user with the name of your pool.

Categories

Resources