Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

ADO.NET: Exception...target of an invocation, when using WebConfigurationManager outside of Try Catch

$
0
0

I’m in the process of creating several Crystal Reports that will use an ADO.NET datasources that were generated using datasets generated from a classes shared functions .  When creating my second report, Crystal Designer reported an error after choosing the method from my new class.  The error was:

“Login Failed.  Details: mscorlib: Exception has been thrown by the target of an invocation.”

I didn’t have this issue at all with my first report.  To validate the dataset, I created a test web page which I linked the same dataset to a data grid and it worked just fine.

It took me a while, comparing the code between my classes and changing the new class one line at a time to match the working class, but I figured out the cause.  In my new class, I was using multiple databases for the source of creating the dataset being returned in my new class.  As part of that, I was making a call to get the connection string to the database from my web.config.  Basically this line was causing the error:

Dim ConnStr as String = WebConfigurationManager.ConnectionStrings.Item("oConnectionString").ToString()

I found if I wrapped it in a Try Catch, the error went away when trying to link to it in CR Designer.  I had all my other .NET calls wrapped in a Try Catch in my first class and that is why I didn’t get this error before.  This one was not easy to figure out the conditions as to how “make things work”.  The error message was little to generic to even suggest what was wrong too.

I am still puzzled as to why a Try Catch fixed the issue with CR Designer though.  Also I would like to know if the code really was my in error or is this a bug in CR Designer.

I've attached sample code images of the error.


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>