System.TimeoutException: Cannot acquire MainDom
a
Hi, I'm running Umbraco 13, when testing and debugging through Visual Studio it works fine but when hosting it through IIS Manager I get the following error: Unhandled exception. System.TimeoutException: Cannot acquire MainDom at Umbraco.Cms.Core.Runtime.MainDom.Acquire() at Umbraco.Cms.Core.Runtime.MainDom.<>c__DisplayClass12_0.b__0() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) at Umbraco.Cms.Core.Runtime.MainDom.Acquire(IApplicationShutdownRegistry hostingEnvironment) at Umbraco.Cms.Infrastructure.Runtime.CoreRuntime.AcquireMainDom() at Umbraco.Cms.Infrastructure.Runtime.CoreRuntime.StartAsync(CancellationToken cancellationToken, Boolean isRestarting) at Umbraco.Cms.Infrastructure.Runtime.CoreRuntime.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.Internal.Host.b__15_1(IHostedService service, CancellationToken token) at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation) at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) at BhaktiMargaBhajanSite.Program.Main(String[] args) I have set full control permissions on the root folder of the application for IIS_IUSRS, any ideas?
Ok I have discovered from the logs it's to do with the sql connection... now my next question is how do I reconfigure my umbraco project to use sql server?
w
Hey there, you should be able to do this by adding a connection string to your app settings JSON file which points to the database hosted on your SQL server instance. You'll need to restore a copy of your current Umbraco db onto that SQL server instance first
a
hey @weedroid , thanks I've already done that but it's giving me an sql timeout error on my IIS server app
the stranger thing is that I've tried commenting out the umbracoDbDSN connection string on my local visual studio app, to test if it is really reading from my db and it seems to run without any problems
so I am now very confused and can't figure out what's going on. been combing through documentation and it's pointing towards all the things I've already done
w
Out of curiosity - is the IIS instance running on your dev machine, or is this on another server in a different environment?
a
both, initially in a remote server with the database set up on the sql server there. I'm now testing it locally on a local instance of IIS
any ideas? @weedroid
to clarify, I've commented out the umbracoDbDSN connection string and for some reason it still works when I run it on visual studio
w
None specific, sorry. Is there anything in the SQL server logs which might give more info about why the timeout's occurring?
If you've commented out the app settings connection string, I'm sure that means it falls back to SQLite by default
a
it's strange, I've tested the connection string and it definitely works
also there is nothing in my sql logs that corresponds to this sql timeout
k
Sounds like it's not picking up the connection string. Is it in the correct file for the environment? I.e.,
appSettings.x.json
. Also, isn't there a log entry that shows part of the connection string? Or at least the database configuration. VS will set the
ASPNETCORE_ENVIRONMENT
but an IIS site will get it from
Web.config
or machine/site configuration
a
I've checked all of that and made sure it's in the right appSettings file. it's still giving me a "cannot acquire MainDom" error. It is not outputting to the log filed stored in the umbraco directory anymore either, so I have no way of figuring out what could be wrong.
k
That's strange. If you enable
stdoutLogEnabled
and/or start Umbraco manually (from the command-line), does it say anything?
a
I think I've found something to work from. After stepping through the startup and configuration code in the program.cs, it seems to be getting its configuration from environment variables https://cdn.discordapp.com/attachments/1238938567829360712/1239593778134646794/image.png?ex=66437d2b&is=66422bab&hm=d3a1c60842f35a9172a56312e963e0be5ecf3aa7c3dd7c82dd91136b79fe0a82&
after losing interest from a lot of time spent going round in circles, I'll probably try investigating how it's pulling umbracoDbDSN value... but really this has been a huge disappointment based on the amount of effort it's taking me to get a .NET app configured to use an sql server connection string...
"This list is in order of precedence, so the values from appsettings.json will only be used if they're not also defined in the environment variables. If they are, then the environment variable will be used instead." there is no equivalent value for umbracoDbDSN in my environment config so I don't see what the problem is here
nothing is showing up in stdoutlog and starting from command-line is giving the same error in the initial post
k
That doesn't look like Umbraco 13 code, it should just be the
Program.cs
without even a class... or is that Umbraco source code you're stepping through somehow? It looks curiously similar to Umbraco 9 code. Is this an upgraded project?
If you make a custom API controller (not an
UmbracoApiController
) and dump
IConfiguration
, are there any `umbracoDbDsn`s in there? Or anything at all from your appSettings.
a
this is all boilerplate code from Umbraco 13.0.3, the only thing I've added are a few controllers and views. it does appear to be populating umbracoDbDsn in the IConfiguration: https://cdn.discordapp.com/attachments/1238938567829360712/1239847462563352607/image.png?ex=6644696e&is=664317ee&hm=2a37a334b4b8a3f86b5a291bfbf0c660b4080e8415268db076816125bf5f2710&
it may not actually be a sql connection problem, since I've just realised the error from the logs I'm going off of is from 2-3 days ago and could be something to do with my VS debug copy (I had to copy my umbraco folder manually into the wwwroot publication folder because VS didn't include this in the published files) I really don't know where else to look to debug this app, there's nothing showing up in event viewer other than the error in the initial post and nothing new showing up in Umbraco logs, nor is there anything in stdout. Any advice would be really appreciated, thanks! 🙏
just to make it clear, it is working completely fine when I run it from VS!
also, I have updated Umbraco to the newest version on the off chance it would fix this issue
k
I don't understand how that can be 13 boilercode. If you dotnet new an Umbraco project, do you get a Startup with ConfigureServices etc? Are you sure the dotnet Umbraco templates are 13.latest?
a
this is the boilerplate code that comes with 13.03, you can confirm by running: dotnet new -i Umbraco.Templates::13.0.3 dotnet new umbraco -n "MyProject" dotnet run --project "MyProject" I didn't update the templates to latest as it was originally written with version 13.03
s
friends.. how are you publishing your app? this is the step where you tell dotnet which appsettings file to use:
dotnet publish -c Release -o  .\release
uses
Release
configuration (
-c Release
) and in turn that uses the
appsettings.Production.json
. I can't remember how exactly though, which is annoying. But are you sure that you have an
appsettings.Production.json
and that contains the correct sql connection string? Otherwise, everything falls back to
appsettings.json
(unless there's environment variables on the server, they take precedence) so if a value is not in
appsettings.Production.json
, it will use the
appsettings.json
setting instead. So before you deploy, you can also just ONLY provide
appsettings.json
and have the correct connection string in there. All of this is not magic, we're using dotnet default behavior for this.
s
Ah yes, I remember now, still do
dotnet publish -c Release
etc, but it will not influence which appsettings file is used. The SERVER has server variables forcing that string.
a
my appSettings.development is also identical
s
You shouldn't be publishing in debug mode, definitely in Release mode
a
also, publishing this way does not include the umbraco folder or media folder
I'll try release later, but do you think this is likely to fix the issue?
k
When I asked about this yesterday you said you had verified that appSettings on the target server had the correct contents. Otherwise, just make sure appSettings.json on the target server has the correct connection string and that there are no other appSettings files.
s
So the server owner should be able to tell you which setting is set for
ASPNETCORE_ENVIRONMENT
- https://stackoverflow.com/questions/46364293/automatically-set-appsettings-json-for-dev-and-release-environments-in-asp-net-c If it's set to
Development
,
appsettings.Development.json
is used, if set to
Production
,
appsettings.Production.json
is used, etc.
Also your hosting provider can be overriding anything in your
appsettings.*.json
files, usually they give you access to environment variables, even if it's just read-only, that might help determine if something is wrong.
k
When I do that, I only get a
Program.cs
. So I don't understand how you can get the pre-13 "Startup"-style code.
a
thanks @Sebastiaan , this seems like a likely cause, I'll be sure to give this a shot later today!
I have absolutely no idea, however I for sure didn't write it and I am the only contributor of my project. It is what came with the nuget install
unless I upgraded from an older version of Umbraco
s
It probably isn't by the way! Your hosting provider wouldn't be overriding things that are specific to Umbraco, that would be weird.
a
which could have been the case, since it's been a few months since I've looked at this project
I'll give it a shot and give you an update
k
I also mentioned the ASPNETCORE_ENVIRONMENT yesterday and where it comes from in IIS/Windows/Azure, maybe I should have been more clear 🙂
a
thanks people, I'll report back later
appreciate all the help here!
k
Is
localhost\SQLEXPRESS01
the correct SQL server instance for the non-working environment? Are you sure that instance is working and reachable on that address? Usually
.
is used for
localhost
with Windows & SQL Server. If that instance isn't running or isn't reachable it would give the timeout error after a while. Easiest way to test is to run SSMS on the server and attempt to connect to
localhost\SQLEXPRESS01
or
.\SQLEXPRESS01
. Also, SQL Server needs to be configured to use the correct protocols; I don't think the default client settings will use anything other than TCP to connect.
a
alright friends, I want to thank you all for all the consideration and help on this issue
I finally got it fixed 🙂
what the issue was, was that on my local IIS, I had some configuration error that was stopping it from even getting into the code. I then checked the umbraco logs on my remote machine and realised that the IIS AppPool user lacked permissions to access the database. Upon adding the appropriate permissions, everything ran perfectly 😄
Thanks again and apologies for the waste of time here 😅
For future reference though, how do I ensure that the media folder is included when I publish the application?
s
I feel like this should have happened automatically on build.. but: https://github.com/umbraco/Umbraco-CMS/issues/14877 However, I suspect it didn't work for you since the permissions were wrong to begin with - meaning the folder was not allowed to be created. There is a possibly helpful comment at the end there though https://github.com/umbraco/Umbraco-CMS/issues/14877#issuecomment-2087206560 from
mmusameh
- noting that if you create the solution in Visual Studio, it might just be to uncheck a box 🤔
429 Views