Tuesday, July 12, 2011

Crm 2011–Request Error in the OrganizationData.svc


I fought this error for an hour this afternoon.  I was setting the the URL to the OrganizationData.svc like so HTTP://CRMDEV-VPC:5555/XRMSERVICES/2011/ORGANIZATIONDATA.SVC/.  This always returned “Request Error” in blue bold letters followed by
The server encountered an error processing the request. See server logs for more details.
So I enabled tracing and retrieved the following from the trace log:
[2011-02-16 16:55:35.910] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread:    7 |Category: Platform.Sdk |User: 00000000-0000-0000-0000-000000000000 |Level: Error | ServiceModelTraceRedirector.TraceData
While this error may appear to be unhelpful, it really tells us  quite a bit.  Notice the Organization and the User are set to an empty GUID.  This is clearly an issue. Crm 2011’s OrganizationData.svc requires the Organization name be present in the the URL.  So the fix was quite simple, add the organization name to the URL:
Hope this saves someone some time.

Crm 2011 Enabling Tracing with PowerShell


Tired of digging through the registry to enable tracing in Crm? Well, you can use PowerShell to enable/disable tracing in Crm 2011. Most of this script is from HTTP://SUPPORT.MICROSOFT.COM/KB/907490 but I had to make a few changes to get it to work. 
THE FOLLOWING POWERSHELL ENABLES TRACING:
Add-PSSnapin Microsoft.Crm.PowerShell
Get-CrmSetting TraceSettings
$setting = Get-CrmSetting TraceSettings
$setting.Enabled=1
Set-CrmSetting $setting
Get-CrmSetting TraceSettings
IISRESET
THE FOLLOWING POWERSHELL DISABLES TRACING:
Add-PSSnapin Microsoft.Crm.PowerShell
Get-CrmSetting TraceSettings
$setting = Get-CrmSetting TraceSettings
$setting.Enabled=0
Set-CrmSetting $setting
Get-CrmSetting TraceSettings
IISRESET
I changed the “True” and “False” from the KB article to 0 and 1 because “False” did not work.  I also added an IISRESET to the end, which is required to turn tracing on or off.
Executing the scripts in Server 2008 R2 is simple, just right click execute PowerShell. 
Enjoy!

Microsoft.ReportViewer.Webforms version error


After you the report viewer you may get the following error when trying to use the ReportViewer Control:
CS0433: The type ‘Microsoft.Reporting.WebForms.ReportViewer’ exists in both ‘c:\WINDOWS\assembly\GAC_MSIL\
Microsoft.ReportViewer.WebForms\8.0.0.0__b03f5f7f11d50a3a\
Microsoft.ReportViewer.WebForms.dll’ and ‘c:\WINDOWS\assembly\GAC_MSIL\
Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\
Microsoft.ReportViewer.WebForms.dll’
The following will force the control to always use version 9.0 of the control.  Add the following to your web.config:

   
     
                                  publicKeyToken=”b03f5f7f11d50a3a” />
                                newVersion=”9.0.0.0″/>
     

   

 
Hope this helps.

Monday, June 14, 2010

My First F# App

I wanted to learn the basics of F# so i wrote a little app to organize my movie folder.  My movie folder was a folder that contained a bunch of movies.  I wanted to organize the movies alphabetically into folders with the first letter being the name of the folder.  After getting used to the syntax of F#, i found writing this little app to be just a easy as C#.
Here is the code:
Code Snippet
  1. #light
  2.  
  3. open System
  4. open System.IO
  5.  
  6. let title : string = "My Movie Organizer"
  7.  
  8. Console.WriteLine(title)
  9.  
  10. Console.WriteLine("This Application will move all files in a folder to subfolders with the first letter as the folder name.")
  11.  
  12. Console.WriteLine("Please enter the path of the folder you want to organize")
  13. let folderPath : string = Console.ReadLine()
  14.  
  15. if folderPath <> String.Empty then
  16.  
  17.     let dirInfo : DirectoryInfo = new DirectoryInfo(folderPath)
  18.  
  19.     for x : FileInfo in dirInfo.GetFiles() do
  20.         let firstLetter : char = x.Name.Chars 0
  21.     
  22.         let currentDirectory : DirectoryInfo = new DirectoryInfo(String.Format("{0}\\{1}\\", folderPath, firstLetter.ToString()))
  23.  
  24.         //If the current folder exists, move the file there else create the folder then move th file
  25.         if currentDirectory.Exists then
  26.             let xFilePath : string = currentDirectory.FullName
  27.             x.MoveTo(xFilePath + x.Name)
  28.         else
  29.             currentDirectory.Create()
  30.             let xFilePath : string = currentDirectory.FullName
  31.             x.MoveTo(xFilePath + x.Name)        
  32.         //Write out the file name and path    
  33.         Console.WriteLine(String.Format("Moving File {0} to Folder {1} ", x.FullName, currentDirectory.FullName))
  34. else
  35.     Console.WriteLine("Please specify a base path")
  36. //Wait for key press to end
  37. let endValue : string = Console.ReadLine()
Being a C# developer, i couldn’t help but explicitly type my variables (although unnecessary).  The first couple of lines are just writing out some text and waiting for the user to enter a path to a folder the want organized.  Next, the base folder path is opened as a directory info object.  Then we loop through all of the files in the directory and grab the first letter of the file name.  After checking if the folder exists, we either move the file or create the new folder and move the file.  The readline at the end just waits for the user to enter a key to end the program.
This is a very simple app and by no means enterprise level with error checking ,etc.  Just a basic app to move some files around in F#.

Sunday, June 6, 2010

How to get the CrmService URL without using the registry

Yes, the Crm Service URL is available in registry but what if the client does not want your custom web page/site to have access the registry? Well here is a simple way to build the SDK URL from the Request object in a web page.

Assumptions:

  • Your page lives in the CrmWeb/ISV folder
    • Which means you custom page will have the same URL as the SDK
  • If you are using an ISV page in a multi org deployment, be sure to use the prependOrgName function or manually append the org name to ISV URL
    • var sUrl = prependOrgName("/ISV/Ascentium/mypage.aspx”)
    • prependOrgName is an unsupported Crm Function.

First the URL Template and the URI Property:

private const string CRM_SDK_URL = "{0}{1}{2}:{3}/mscrmservices/2007/crmservice.asmx";

private Uri _currentUri;

/// <summary>
/// Gets the current URI.
/// </summary>
/// <value>The current URI.</value>
private Uri CurrentUri
{
get
{
if (_currentUri == null)
{
_currentUri = this.Request.Url;
}
return _currentUri;
}
}


Now we use string.Format to create the SDK URL from the URI and the Template:



private CrmService _service;
/// <summary>
/// Gets the current service.
/// </summary>
/// <value>The current service.</value>
private CrmService CurrentService
{
get
{
if(_service == null)
{
_service = new CrmService();
_service.CrmAuthenticationTokenValue = CrmAuthenticationToken.ExtractCrmAuthenticationToken(this.Context, "MY_ORG");
_service.Url = string.Format(CRM_SDK_URL, CurrentUri.Scheme, Uri.SchemeDelimiter, CurrentUri.Host, CurrentUri.Port);
}

return _service;
}
}



And that is it.  Now the SDK Url can be built dynamically from the Request. This method could be adapted to fit other scenarios as well.