[dba-VB] Object Reference not set to an Object error

David Emerson newsgrps at dalyn.co.nz
Wed Jul 18 17:15:04 CDT 2007


Thanks Eric,  Another topic to digest.

David

At 19/07/2007, you wrote:
>Use Try...Catch
>
>Try
>         ' Statement which can cause an exception.
>         If CType(rpt.DataSource,
>DataDynamics.ActiveReports.DataSources.SqlDBDataSource).ConnectionString.ToS
>tring <> "" Then
>                 CType(rpt.DataSource,
>DataDynamics.ActiveReports.DataSources.SqlDBDataSource).ConnectionString =
>System.Web.Configuration.WebConfigurationManager.ConnectionStrings("IFADBCon
>nection").ConnectionString
>         End If
>
>Catch x As Type
>         ' Statements for handling the exception
>Finally
>
>End Try 'Any cleanup code
>
>
>
>-----Original Message-----
>From: dba-vb-bounces at databaseadvisors.com
>[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of David Emerson
>Sent: Wednesday, July 18, 2007 12:20 PM
>To: dba-vb at databaseadvisors.com
>Subject: [dba-VB] Object Reference not set to an Object error
>
>I use an add on from DataDynamics called ActiveReports which alows me to
>produce dot net reports in a similar interface to Access (sort of).
>
>I have a connection string defined in my Web.Config file.  I want to set the
>connection string of the report to this when the report is run.  I have the
>following code which is supposed to check whether the report has a
>connection string already.  If the report doesn't have a connection string
>then I don't want to add a connection string (because there is no data for
>the report), otherwise I want to replace the connection string with the one
>in the Web.Config.
>
>If CType(rpt.DataSource,
>DataDynamics.ActiveReports.DataSources.SqlDBDataSource).ConnectionString.ToS
>tring
><> "" Then
>         CType(rpt.DataSource,
>DataDynamics.ActiveReports.DataSources.SqlDBDataSource).ConnectionString
>=
>System.Web.Configuration.WebConfigurationManager.ConnectionStrings("IFADBCon
>nection").ConnectionString
>End If
>
>The problem is with the first line.  If there is a connection string then it
>is replaced.  If the report doesn't have a connection string then an error
>is raised at the first line saying "Object reference not set to an instance
>of an object".  My guess is that this is because no data source is set at
>all for the report there is no ConnectionString object to compare to.
>
>Can anyone please help with the syntax for checking whether the data source
>object exists (then if it does I can make the replacement to the
>connectionString).
>
>
>Regards
>
>David Emerson
>Dalyn Software Ltd
>Wellington, New Zealand
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com
>
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.476 / Virus Database: 269.10.8/906 - Release Date: 7/17/2007
>6:30 PM
>
>
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com




More information about the dba-VB mailing list