9. May 2011 15:42
To import an organization in Microsoft CRM 2011, you can use the deploymentservice by using the BeginImportOrganizationRequest. See the code sample below
BeginImportOrganizationRequest request = new BeginImportOrganizationRequest();
request.DatabaseName = "DATABASE_MSCRM"; //Name of the database which must be present at the sql server, includig _MSCRM on the end
request.FriendlyName = "Company name"; //Name of the company
request.SqlServerName = "http://sql01"; //url of the sql server
request.SrsUrl = "http://srs01"; //url of the report server
request.UniqueName = "DATABASE"; //name of the databse, excluding _MSCRM on the end
request.UserMappingMethod = ImportUserMappingMethod.ByMappingXml;
request.UserMappingXml = "C:\\temp.xml"; //Location of the xml
BeginImportOrganizationResponse response = (BeginImportOrganizationResponse)Provider.deploymentservice.Execute(request);
Note that the Request is an asynchronous request. Once you recieve the response, the database is not yet fully imported, it is just starting. In this example we use an xml file to map users. Below you find a sample xml file
<MappingConfiguration><DomainMapping old=\"domainA\" new=\"domainB\" /><UserMapping old=\"domainA\\administrator\" new=\"domainB\\administrator\" /></MappingConfiguration>
Make sure that u include the user who runs the code in the mapping xml as one of the users, otherwise you will get the error below:
you must map your active directory user account to at least one enabled Microsft Dynamics CRM user who has the System Administrator security role before the organization can be imported