24 November 2010

Import Organisation, change to default, gives Invalid User Authorization Error

When importing an organisation into Dynamics CRM 4.0 and making it default you sometimes come across the "Invalid Authorization error" message even though you're logged in as the System Administrator.

The following TSQL should be run on the SQL instance that hosts the CRM databases. It isn't a supported fix and I take no responsibility if it breaks your system. Remember backups are your friend!

The scripts have been taken from other resouces on the t'internet, but I can't remember where. When I find out I will acknowledge the original authors hard work.

-- Import Organisation, change default, gives Invalid User Authorization error
-- To Resolve this issue it is necessary to change the user's default organisation

--STEP 1
DECLARE @Org nvarchar(50)
set @Org = 'MSCRMORGNAME'

DECLARE @OrgDb nvarchar(150)
set @OrgDb= @Org + '_MSCRM'


DECLARE @UserName nvarchar(50)
set @UserName='DOMAIN\username'

execute ('select OrganizationId from ' + @OrgDb +'..organization where name=''' + @Org +'''')
execute ('select systemuserid, DomainName from ' + @OrgDb +'..SystemUserBase where DomainName='''+ @UserName + '''')


--STEP 2
-- User the systemuserid returned to get the correct GUID
select userid from MSCRM_CONFIG..systemuserorganizations where crmuserid = '[systemuserid]'

-- Use the userid to return the correct
select DefaultOrganizationId from MSCRM_CONFIG..systemuser where id = '[userid]'

--Use the DefaultOrganizationId and userid to update the table
update MSCRM_CONFIG..systemuser set defaultorganizationid = '[DefaultOrganizationId]' where id = '[OrganizationId]'

10 November 2010

CRM 4 ISV Web App Error Out

Sometimes when a web application has been deployed to the ISV folder within CRM it doesn't work instead it gives a Runtime Error.

To resolve this the web application's web.config file needs to be updated to include the following (immediately above the tag: </httpModules>)

<remove name="CrmAuthentication">

Note: You will probably need to comment the line out if you're testing the code through Visual Studio.

This is necessary because the ISV web application is inheriting from the parent CRM web site.

Hosting a virtual app With a Different .Net version

An error will occur if you try and host a web application within a web site and mix the .Net versions. This is because the virtual application will attempt to inherit from it's parent. This can be switched off by editing the parent web.config as follows:

Wrap <system.web> with:
<location path="." inheritinchildapplications="false">

For Example:

<location path="." inheritinchildapplications="false">
<system.web>
...
</system.web>
</location>