web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

MSCRM, sql select error invalid column name

(0) ShareShare
ReportReport
Posted on by 20

Hello, we are trying to get some data from Account entity in MSCRM 8 onpremise

we have sql query something like this (It is called from c# application):

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:

System.Data.SqlClient.SqlException: Invalid column name 'acc.v_ownerid'.

The field 'acc.v_ownerid' for 100% exists in DB

  1. If I will run this select in Sql Management studio it will give me result
  2. If I run SQL profiler I will get sql query, which also returns result
  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..

Please where can be the problem?

Petr

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I work with Dynamics since 2008 and v 4.0 and I did some DB-side work as well. I never heard or seen v_ownerid field.

    Question - what is stored in this field and why do you need it?

  • petrtim Profile Picture
    20 on at

    It is custom  field...

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Can you please provide code where you build SQL Connection, where you use SQLCommand and/or SQLAdapter and so on including your SQL Connection string?

  • Verified answer
    petrtim Profile Picture
    20 on at

    Well, the solution is to use this 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...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans