I am pulling a set of records to use the CrmServiceClient to upload them into a custom entity in our instance of CRM.
The query is returning results and seems to be setting the fields in sms properly.
The error is being thrown at this line: Guid NewActid = crmService.Create(sms);
Any idea what is causing this?
ERROR Details:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=UploadLeads_toCRM
StackTrace:
at UpdateCRM.Program.HMtoCRM() in C:\...\UploadLeads_toCRM\Program.cs:line 149
at UpdateCRM.Program.Main(String[] args) in C:\...\UploadLeads_toCRM\Program.cs:line 32
CODE:
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader r = command.ExecuteReader();
var p = 0;
while (r.Read())
{
Console.WriteLine(r["contactid"].ToString());
Console.WriteLine(r["date"].ToString());
Console.WriteLine(r["messages"].ToString());
var messages = r["messages"].ToString();
var sms = new ksl_sms
{
ActualStart = DateTime.Parse(r["date"].ToString()),
ActualEnd = DateTime.Parse(r["date"].ToString()),
ksl_Contact = new EntityReference("contact", Guid.Parse(r["contactid"].ToString())),
RegardingObjectId = new EntityReference("contact", Guid.Parse(r["contactid"].ToString())),
OwnerId = new EntityReference("systemuser", Guid.Parse(r["ownerid"].ToString())),
ksl_completeby = new EntityReference("systemuser", Guid.Parse(r["ownerid"].ToString())),
StatusCode = new OptionSetValue(1),
ksl_TextsReceived = Convert.ToInt16(r["totalreceived"]),
ksl_TextsSent = Convert.ToInt16(r["totalsent"].ToString()),
Description = r["messages"].ToString(),
Subject = "Text Conversation"
};
Guid NewActid = crmService.Create(sms);