Hello, We have a multitenancy web application, with one master database which holds the administration data and (n) databases to hold tenants data.

we Use SessionManager to handle Master database and create and build the tenants domains manually.

to build the company database we extract the company database login info from the master database and perform the build in web application(according to login tenant).

lately we move this operations to an Application manager, which is a desktop application which responsible to create the database( using SQL and ADO.net), then build it using Domain.Build method(just as done in web application).

the problem is that if the database is new we get System.OutOfMemoryException, which is not happened when build from web application, this happens before and solved by modify the Create database statement (just with the create statement from SQL Server Management Studio), but suddenly its returned back and being a stopper issue. I only noticed that, if I build it before building the master database domain, it works. is there are a known issue regarding what I do, or something I should do to solve the problem? The stack trace:

at System.Text.StringBuilder.ToString()
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(String format, Object[] args)
   at Xtensive.Modelling.Comparison.Difference.ToString()
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at Xtensive.Modelling.Comparison.NodeDifference.ParametersToString()
   at Xtensive.Modelling.Comparison.Difference.ToString()
   at Xtensive.Orm.Upgrade.SchemaComparisonResult.ToString()
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.SynchronizeSchema(Domain domain, SchemaUpgrader upgrader, SchemaExtractor extractor, SchemaUpgradeMode schemaUpgradeMode)
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.PerformUpgrade(Domain domain, UpgradeStage stage)
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.BuildMultistageDomain()
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.Run()
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.Build(DomainConfiguration configuration)
   at Xtensive.Orm.Domain.Build(DomainConfiguration configuration)
   at Microtech.Andalus.Business.SchedulingServiceDomainManager.BuildNewCompany(Company company) in D:\Fawzy\SVN\Framework\Microtech.Andalus.Business\Core\SchedulingServiceDomainManager.cs:line 183

asked Dec 11 '14 at 10:05

ahmad%20emad's gravatar image

ahmad emad

One Answer:

Hi ahmad emad.

Your stack trace tells that OutOfMemoryException throws when DO tries to form message about difference between current schema of database and DO model and to log this message. I suppose that difference is very big and takes a lot of memory on conversion to string.

Is the model, which takes DO throwing OutOfMemoryException, big? Do you have enough memory?

If database is new and there is no fear of losing data then you can build domain in Recreate mode. In this mode DO don't dump difference to log message.

answered Dec 12 '14 at 04:07

Alexey%20Kulakov's gravatar image

Alexey Kulakov

edited Dec 12 '14 at 04:08

Hello Alexey, the model is big, but its built without any problem when doing build from web application instead of desktop application, also in desktop application, when I build the tenant database before building the master database it works fine.

regarding the recreate mode, it solves the problem, but I need to be sure that the database is empty, so is there is any way to know that before start build(without using direct SQL & ADO.net)?

(Dec 14 '14 at 03:43) ahmad emad ahmad%20emad's gravatar image

OutOfMemoryException may thrown when there is no continuous part of memory to allocate demanded amount. In .NET 4.0 memory limit per object is 2 GB (if there is place to allocate), but in .Net 4.5 we can disable this limitation (see this post). According to that post we can create array of 130 000 000 (1,94 GB) elements of ComplextNumber in net 4.0, but on my computer with 8GB memory I can create array with capacity about 81-82 millions of items.

(Dec 15 '14 at 08:38) Alexey Kulakov Alexey%20Kulakov's gravatar image

You can try to use gcAllowVeryLargeObjects option in app.config if you use .Net 4.5 and x64 process. I don't know exactly why web application works fine, but desktop application throws exception. But in case then tenant domain builds before master domain, I suppose, you have enough memory to build tenant domain, otherwise, master domain gets some memory and tenant domain can't get memory which it need.

Unfortunately, there is no way to know that database is empty using DO before building domain.

(Dec 15 '14 at 08:49) Alexey Kulakov Alexey%20Kulakov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Dec 11 '14 at 10:05

Seen: 4,004 times

Last updated: Dec 15 '14 at 08:49

powered by OSQA