0

I have a website that it is asp.net with c# language. I connect to Dynamics CRM with this code :

CrmServiceClient service = new CrmServiceClient("url=my url; Domain=my domain; username=user; password=pass");

and I retrieve all things from CRM to my website,and every thing work well, when I start my website from visual studio. but I have finished my website now, and I want to publish it in my IIS. but when it comes to the first codes that retrieve data from Dynamics CRM like this code :

QueryExpression query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("hi_password", "name", "hi_typeofaccount", "accountnumber") };
query.Criteria.AddCondition("hi_password", ConditionOperator.Equal,Txt_Password .Text );
query.Criteria.AddCondition("name", ConditionOperator.Equal, Txt_UserName .Text );

EntityCollection result1 = service.RetrieveMultiple(query);

an error occurs with this title:

Object reference not set to an instance of an object

I don't have any error when I start my website from visual studio.

Arun Vinoth
  • 20,360
  • 14
  • 48
  • 135
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Tom W Jul 16 '19 at 15:57

1 Answers1

0

"Object reference not set to an instance of an object" means that you try to access a property of something that is NULL.

Example: If you try to access something like Account.EntityReference.Id and the EntityReference == NULL you will get this kind of error.

Your query looks fine. try to check the value of Txt_Password & Txt_Username when executing the query ?

Vincent V
  • 1
  • 5
  • i told that every thing is ok when i execute from vs but i have this problem when i publish my web site in iis and i browse my website – vashtihatami Jul 16 '19 at 15:40