简体   繁体   English

MSCRM,sql select 错误列名无效

[英]MSCRM, sql select error invalid column name

trying to get some data from Account in MSCRM 8 onpremise试图从内部 MSCRM 8 中的帐户获取一些数据

we have sql query something like this:我们有 sql 查询如下:

select distinct top 100 acc.accountid,acc.OwnerId, ...,  acc.v_ownerid 
from account acc
where acc.statecode = 0 and (1=0 or acc.accountid= xxxx)

When I Try to run this select from my C# code I am getting an error:当我尝试从我的 C# 代码运行此 select 时,出现错误:

System.Data.SqlClient.SqlException: Invalid column name 'acc.v_ownerid'. System.Data.SqlClient.SqlException:列名“acc.v_ownerid”无效。

The field 'acc.v_ownerid' for 100% exists in DB数据库中存在 100% 的字段“acc.v_ownerid”

  1. If I will run this select in Sql Management studio it will give me result如果我将在 Sql 管理工作室运行这个 select 它会给我结果
  2. If I run SQL profiler I will get sql query, which also returns result如果我运行 SQL 分析器,我将得到 sql 查询,该查询也返回结果
  3. If I will run it from C# code, It will give me error above, if this field is removed it will work, but I need it..如果我从 C# 代码运行它,它会给我上面的错误,如果这个字段被删除它会起作用,但我需要它..

Please where can be the problem?请问可能是哪里出了问题?

Petr彼得

With MSCRM on-prem running SQL queries against the tables is unsupported.使用 MSCRM on-prem 运行 SQL 对表的查询不受支持。

Microsoft supports only two operations against an MSCRM SQL database: Microsoft 仅支持针对 MSCRM SQL 数据库的两种操作:

  1. Creating custom indexes创建自定义索引
  2. Running SELECT queries against the filtered views... eg FilteredAccount.针对过滤的视图运行SELECT查询...例如 FilteredAccount。

In addition to providing the text values for lookups and option sets, the filtered views also enforce security at the database level.除了为查找和选项集提供文本值外,过滤视图还在数据库级别强制执行安全性。

You might want to refactor your SQL to use the FilteredAccount view and see how you make out with that.您可能想重构您的 SQL 以使用 FilteredAccount 视图,看看您是如何做到的。

Also, please note that the Account table is called AccountBase.另外,请注意 Account 表称为 AccountBase。

帐户库

The database object named Account is actually a view (which it is also unspported to query, as it is not a Filtered view.)名为 Account 的数据库 object 实际上是一个视图(它也不支持查询,因为它不是过滤视图。)

帐户视图

The only supported way to query for Accounts in SQL is via the FilteredAccount view:在 SQL 中查询 Accounts 的唯一支持方法是通过 FilteredAccount 视图:

过滤帐户

Well, the solution is to use this select嗯,解决办法就是用这个select

Select distinct top 100 acc.accountid,acc.OwnerId, ...,  acc.v_ownerid from 
X.dbo.account acc
where acc.statecode = 0 and (1=0 or acc.accountid= xxxx)

instead of:代替:

select distinct top 100 acc.accountid,acc.OwnerId, ...,  acc.v_ownerid 
from account acc
where acc.statecode = 0 and (1=0 or acc.accountid= xxxx)

Then it returns all columns, do not know why, but it is working...然后它返回所有列,不知道为什么,但它正在工作......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM