<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>InforPath 2013 Casting problem in FileQueryConnection</title><link>https://www.infopathdev.com:443/forums/thread/103534.aspx</link><pubDate>Wed, 05 Aug 2015 08:30:59 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:103534</guid><dc:creator>Buddhini</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/103534.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=103534</wfw:commentRss><description>Hi All,

I have used FileQueryConnection for update the data connection withing code behind in InfoPath 2007. 
 
FileQueryConnection dataConnection = (FileQueryConnection)DataConnections[&amp;quot;DataConnectionFileName&amp;quot;];
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 &amp;#39;Microsoft.Office.InfoPath.Server.DocumentLifetime.DataAdapterListDataProviderHost&amp;#39; to type &amp;#39;Microsoft.Office.InfoPath.FileQueryConnection&amp;#39;.

Then I have changed the code as below 
FileQueryConnection dataConnection = (FileQueryConnection)(DataSources[&amp;quot;DataConnectionFileName &amp;quot;].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 &amp;#39;Microsoft.Office.InfoPath.Server.DocumentLifetime.DataAdapterListDataProviderHost&amp;#39; to type &amp;#39;Microsoft.Office.InfoPath.FileQueryConnection&amp;#39;.

Can you please help me to resolve this issue.</description></item></channel></rss>