0

I have been trying the following code and error is:

the type and namespace named crmConnection could not be found.

var connection = new CrmConnection();
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
var connection = CrmConnection.Parse("Url=https://xyz.crm.dynamics.com;Username=username1;Password=password1);

Can you please help me?

AlexDrenea
  • 7,981
  • 1
  • 32
  • 49
Max410
  • 51
  • 1
  • 10
  • You need to import the library where `CrmConnection` is or give the full namespace. – DavidG Jul 13 '16 at 12:32
  • Have you added a reference to the dll? Read [this duplicate](http://stackoverflow.com/questions/4764978/the-type-or-namespace-name-could-not-be-found), it might be helpful – Tim Schmelter Jul 13 '16 at 12:33
  • Does it work if you add `using Microsoft.Xrm.Client;` to the top of the file? – DavidG Jul 13 '16 at 12:35
  • There is no class names Client in Microsoft.Xrm. So that does not work. @DavidG – Max410 Jul 13 '16 at 12:38
  • There is no class names Client in Microsoft.Xrm. So that does not work. @DavidG – Max410 Jul 13 '16 at 12:38
  • So then you need to add a reference to it. This is rather basic C# fundamentals, perhaps you need to run through a tutorial first? – DavidG Jul 13 '16 at 12:39
  • using Microsoft.Xrm.Sdk; contains the client class but the application is not able to find it. How to do that? @DavidG – Max410 Jul 13 '16 at 12:40
  • Thank you @TimSchmelter but I am not able to understand the basics. Any further suggestions ? – Max410 Jul 13 '16 at 12:43

2 Answers2

1

I use the following method to connect to the CRM OrganizationService, because I had problems with CrmConnection and Tooling.CrmConnector. This method has been tested for on premise installation with internet facing deployment.

Replace {OrganizationName} and {Servername} with the name of the CRM Organisation and URL of the CRM Server. For example: OrganizationName = "xyz", Servername = "crm.dynamics.com".

using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;

string serviceUri = "https://{OrganizationName}.{Servername}/XRMServices/2011/Organization.svc";
var credentials = new ClientCredentials();
credentials.UserName.UserName = "YourUsername";
credentials.UserName.Password = "YourPassword"; 
var crmOrganizationService = new OrganizationServiceProxy(new Uri(serviceUri), null, credentials, null);

To install the Microsoft.Xrm.Sdk package in a VS project, do the following:

  • right-click on Solution Node in Soltion exploerer, choose "Manage NuGet packages for Solution"
  • in NuGet Explorer, choose "Browse" and search for "CRM SDK 2016"
  • Choose Microsoft.CrmSdk.CoreAssemblies, select the project into which you want to install the package, and click "Install"
Gilad Green
  • 36,708
  • 7
  • 61
  • 95
Georg Patscheider
  • 9,357
  • 1
  • 26
  • 36
  • I did that but it is not helping. Thanks @georg Patsheider – Max410 Jul 13 '16 at 12:50
  • Do you get any errors while installing the package? Your project must target .NET Framework 4.5 or higher if you want to use version 8 of the SDK. Package Manager errors are written to the "Output" window. – Georg Patscheider Jul 13 '16 at 12:53
0

You will need to get the CRM SDK if you dont have it already, then add a reference to the Microsoft.Xrm.Client assembly which contains CrmConnection.

James Wood
  • 17,286
  • 4
  • 46
  • 89