Hi All,
I have used FileQueryConnection for update the data connection withing code behind in InfoPath 2007.
FileQueryConnection dataConnection = (FileQueryConnection)DataConnections["DataConnectionFileName"];
dataConnection.FileLocation = GetFileLocation(); // Get and set the file location for update the data source
dataConnection.Execute();
This code worked properly in InfoPath 2007. But now I have migrate my form in to InfoPath 2013.
But with the code excecution of infopath 2013 this will endup with the below exception.
Exception :
Unable to cast object of type 'Microsoft.Office.InfoPath.Server.DocumentLifetime.DataAdapterListDataProviderHost' to type 'Microsoft.Office.InfoPath.FileQueryConnection'.
Then I have changed the code as below
FileQueryConnection dataConnection = (FileQueryConnection)(DataSources["DataConnectionFileName "].QueryConnection);
( Reference : https://msdn.microsoft.com/EN-US/library/office/microsoft.office.infopath.filequeryconnection.aspx )
But in both cases I came-up with the same exception.
Exception :
Unable to cast object of type 'Microsoft.Office.InfoPath.Server.DocumentLifetime.DataAdapterListDataProviderHost' to type 'Microsoft.Office.InfoPath.FileQueryConnection'.
Can you please help me to resolve this issue.