我们正在使用CRM 2015内部部署,我们正在尝试构建客户门户,因为我们生成了早期绑定类
它已成功生成并添加到VS 2012.现在的问题是当我在VS中构建项目时它很顺利,当我运行项目时它会在自动生成的代码中抛出错误
代码在
之下 public XrmServiceContext()
{
}
以下是我的web.config代码
<?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>
我得到的例外是&#34;无法找到名称为&#34;的连接字符串。
我在调试代码时遇到了这个错误
我按照网站门户网站开发中提到的MSDN网站的每一步,如果我错过了什么请帮我解决这个错误
以下是我的Web.config代码
答案 0 :(得分:0)
您需要在app.config / web.config文件中定义CRM连接字符串。如果您没有指定连接字符串,则客户端DLL默认使用Config文件。
答案 1 :(得分:0)
CRMSvcUtil.exe用于生成一组类,您可以将这些类包含在项目中,然后用于读取和操作CRM数据。但是在创建连接然后实例化并使用它们之前,它们不“做”任何事情。这里介绍了简化的连接字符串方法...... https://msdn.microsoft.com/en-us/library/gg695810.aspx
基本上你在web.config部分放了一个conn字符串,就像这样...
<add connectionString="Url=http://crm.contoso.com/xrmContoso; Domain=CONTOSO; Username=jsmith; Password=passcode" name="Crm" />
然后在你使用早期或晚期绑定对象之前的某个地方,你这样做......
//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);
通过早期绑定,您可以针对生成的代码对象执行LINQ查询,或者 {entity}集 context ,就像这样......
var contacts = (from c in context.ContactSet
where c.LastName == "Smith"
select c);
这将返回一个符合条件的记录集合,您可以使用foreach循环枚举,或绑定到控件,或作为jSON数组发送,或者您想要的任何内容。