Tuesday, May 24, 2011

Encrypt appsettings in web.config


Below are the steps to do this

1)   Encrypt appsettings in web.config using Aspnet_regiis.exe
using Aspnet_regiis.exe you can encrypt whole section only not a particular key.so when you need to encrypt a particular key in appSettings things get complicated. Here is a roundabout way of doing this. Modify your web.config

2)   <configsections>
<section type="System.Configuration.NameValueSectionHandler,System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="secureAppSettings" />

<appsettings>......</appsettings>

<secureappsettings>
<add key="ipwd" value="secure-password"/>
</secureappsettings>
</configsections>

3)   Under secureAppSettings you can add any key value pairs.

Also secureAppSettings is the name i had given. You can give any. Save this web.config file and go to visual studio command prompt

4)   Type

aspnet_regiis -pef secureAppSettings  “ur web.config path”  -prov DataProtectionConfigurationProvider


5)   In code you can access it as usual

NameValueCollection secureAppSettings = (NameValueCollection)ConfigurationManager.GetSection("secureAppSettings")
String str= secureAppSettings["ipwd"];

Saturday, May 21, 2011

SQL Timeouts in CRM 4.0 - import of customizations fail


When importing customizations to CRM 4.0, the import fails with a message "generic SQL error". Digging a bit deeper the error message is really that a timeout has occured. The same error occurs when trying to create a new entity.
I increased the timeout as suggested in the link below
Increasing the timeout:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\OLEDBTimeout
This value does not exist by default, and if it does not exist then the default value will be 30 seconds. To change it, add the registry value (of type DWORD), and put in the value you want (measured in seconds). Then you have to recycle the CrmAppPool application pool for the change to take effect

By Increasing the time out in the registry will solve the problem. Number of seconds depends on the amount of data in the database.


Tuesday, May 10, 2011

Set Lookup Field While Updating/Creating Record from Jscript Using CRM REST End Point


    var newaccount= new Object();
 
    newaccount.neu_name = "test";
    var contact_ref = new Object();
    contact_ref .Id = contactid;
    contact_ref .LogicalName = "contact";
    contact_ref .Name = "test contact";

    newaccount.primarycontactid = neumodelyear_ref;

//createRecord Method is available in jqueryrestdataoperationfunctions.js in SDK
    createRecord(newaccount, "accountSet", createnewaccountcompleted, null);

References:
http://technet.microsoft.com/es-ar/library/gg334767(en-us).aspx
http://technet.microsoft.com/en-us/library/gg309638.aspx
http://technet.microsoft.com/en-us/library/gg309558.aspx
http://msdn.microsoft.com/en-us/library/gg334427(MSDN.10).aspx

Wednesday, May 4, 2011

Generating EarlyBound CRM Entities using crmsvcutil.exe

To generate XRM.cs navigate to the sdk bin folder from the command prompt and use the below command
NOTE: This command works for crm 2011 online environment

CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"   /url:https://crmtest.api.crm.dynamics.com/XRMServices/2011/Organization.svc   /out:Xrm.cs   /username:liveid   /password:password   /deviceid: deviceid /devicepassword: devicepassword   /namespace:Xrm   /servicecontextname:XrmServiceContext  /servicecontextprefix:Xrm


References:
http://msdn.microsoft.com/en-us/library/gg695782.aspx