Ladies and Gentlemen,
your help please.
I have been using CSLA for about three weeks now and read most of the book (up to chapter 9). I'm using VB 2005 and an Oracle 10g DB in a Windows Forms design.
I'm in the process of building a prototype for the rest of the team. This is very much in the line with the Project Tracker example from the download.
So far so good. But I have hit a brick wall. I can't seem to convert from OracleDataReader to the SafeDataReader. I want to take advantage of the implicit null checking.
I have searched the forum but I can't see any resolution to this.
Can anyone tell if this can be done and how?
I have tried CType, DirectCast which compile but give an InvalidCast error at runtime!
Thanks for reading.
Here is the error:
Unable to cast object of type 'Oracle.DataAccess.Client.OracleDataReader' to type 'Csla.Data.SafeDataReader'."}
System.InvalidCastException: {"Unable to cast object of type 'Oracle.DataAccess.Client.OracleDataReader' to type 'Csla.Data.SafeDataReader'
Hi,
You cannot create a SafeDataReader by casting. You should call the constructor of SafeDataReader and pass in the OracleDataReader:
Dim command as OracleCommand
Dim safeReader as SafeDataReader
safeReader = New SafeDataReader(command.ExecuteReader)
Cheers,
Herman
Herman,
Thanks for your reply. It worked! Fantastic.
So we get SafeDataReader and Smartdate all from a few lines of code.
I understand what's happening but I couldn't see in until you explained it. Simple really.
You can create a subclass of SafeDataReader in your BO project so that you can override methods to help you work with Oracle. As I recall, Oracle does not have Bit field like SQL Server does so there is a problem with GetBoolean in SafeDataReader. I use a config file setting to switch between SQL Server and Oracle. I also code my DAL to use IDataReader and return SQLDataReader or OracleDataReader based on the same setting.
Here is my version:
<Serializable()> _
#
Region " Class Variable Declarations "#
End Region#
Region " Properties and Methods " Public Overrides Function GetBoolean(ByVal i As Integer) As Boolean#
End Region End ClassJoe
Thanks Joe
I'm interested to learn how would you do this for the app.config?
I am not sure what you are asking here.
It is just a setting in the config file which you read on app startup.
<appSettings file="user.config">
<add key="Authentication" value="CSLA"/>
<add key="DBType" value="SQL Server"/>
<!-- <add key="DBType" value="Oracle" /> -->
<add key="ConnectionString" value="data source=joe;database=myDB;uid=myUser;password=myPwd"/>
</appSettings>
Joe
Public Shared ReadOnly Property AppSettings() As System.Collections.Specialized.NameValueCollection
Member of:
System.Web.Configuration.WebConfigurationManagerSummary:
Gets the System.Configuration.AppSettingsSection data for the current Web application's default configuration.
Return Values:
A System.Collections.Specialized.NameValueCollection object containing the System.Configuration.AppSettingsSection object for the current Web application's default configuration.
Exceptions:
System.Configuration.ConfigurationErrorsException: A valid System.Collections.Specialized.NameValueCollection object could not be retrieved with the application settings data.
Of course it is, thanks Joe
Copyright (c) Marimer LLC