-1

We are using CRM 2015 on-premise, we are trying to build customer portal, for that we generated Early Bound class

It is successfully generated and added to VS 2012. Now the problem is when i build the project in VS it goes fine and when i run the project it throws error in the Auto generated code

The code is below

    public XrmServiceContext()
    {

    }

Below is my web.config code

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="Microsoft.Xrm.Client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
  </configSections>
  <connectionStrings>
    <add name="Xrm" connectionString="ServiceUri=http://Contoso/XRMServices/2011/OrganizationData.svc/; Domain=MyDomain; Username=vsaravanakumar; Password=Password@5"/>   
  </connectionStrings>
  <Microsoft.Xrm.Client>
    <contexts>
      <add name="Xrm" type="Xrm.XrmServiceContext, WebAppWalkthrough"/>
    </contexts>
  </Microsoft.Xrm.Client>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
      <controls>
        <add tagPrefix="crm" namespace="Microsoft.Xrm.Portal.Web.UI.WebControls" assembly="Microsoft.Xrm.Portal"/>
      </controls>
    </pages>
    <authentication mode="None"/>
  </system.web>
</configuration>

The exception im getting is "Unable to find connection string with name".

I got this error during debugging of my code

I followed each and every steps what MSDN website is mentioned in the website portal development, if i missed anything please help me to resolve this error

Below is my Web.config Code

Saravana kumar
  • 33
  • 1
  • 12

2 Answers2

0

You need to define the CRM connection string in your app.config/web.config files. If you don't specify a connection string the Client DLL defaults to using the Config file.

Nicknow
  • 7,154
  • 3
  • 22
  • 38
0

The CRMSvcUtil.exe is used to generate a set of classes that you can include in your project and then use to read and manipulate CRM data. But they don't "do" anything until you create a connection and then instantiate and use them. The simplified connection string method is covered here... https://msdn.microsoft.com/en-us/library/gg695810.aspx

Essentially you put a conn string in web.config section like this...

<add connectionString="Url=http://crm.contoso.com/xrmContoso; Domain=CONTOSO; Username=jsmith; Password=passcode" name="Crm" />

Then somewhere before you use early or late bound objects, you do this...

//Use the Microsoft Dynamics CRM Online connection string from the web.config  (or app.config) file named "CRM".
var connection = new CrmConnection("CRM");
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);

With early bound you then can do a LINQ query against the generated code objects or {entity}Sets of the context like this...

var contacts = (from c in context.ContactSet
                where c.LastName == "Smith"
                select c);

This will return a collection of records matching your criteria that you could enumerate through with a foreach loop, or bind to a control, or send as a jSON array, or whatever you'd like.