This is a migrated thread and some comments may be shown as answers.

[Solved] VB multi-value Scheduler Provider error

3 Answers 200 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
jonnyO
Top achievements
Rank 1
jonnyO asked on 15 May 2008, 06:37 AM
Trying to implement a VB rendition of the multi-value resources example I'm getting error in my web.config.  Any ideas are appreciated.

web.config
    <configSections> 
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">  
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">  
                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" /> 
                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">  
                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" /> 
                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" /> 
                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" /> 
                </sectionGroup> 
            </sectionGroup> 
        </sectionGroup> 
        <sectionGroup name="telerik.web.ui">  
            <section name="radScheduler" type="Telerik.Web.UI.RadSchedulerConfigurationSection, Telerik.Web.UI, PublicKeyToken=121fae78165ba3d4" allowDefinition="MachineToApplication" requirePermission="false" /> 
        </sectionGroup> 
    </configSections> 
 
...  
 
    <telerik.web.ui> 
        <radScheduler defaultAppointmentProvider="Integrated">  
            <appointmentProviders> 
                <add name="AppDbSchedulerProvider" 
                    connectionStringName="dbMemberConnString" 
                    type="AppScheduler.AppDbSchedulerProvider"   
                    persistChanges="true" /> 
            </appointmentProviders> 
        </radScheduler> 
    </telerik.web.ui> 

web.config error:
Parser Error Message: Cannot create an abstract class.

Source Error:

Line 202:				<add name="AppDbSchedulerProvider"
Line 203:					connectionStringName="dbMemberConnString"
Line 204: type="AppScheduler.AppDbSchedulerProvider" Line 205:					persistChanges="true" />
Line 206:			</appointmentProviders>

Provider code:

Imports System  
Imports System.Collections.Generic  
Imports System.Collections.Specialized  
Imports System.Configuration  
Imports System.Configuration.Provider  
Imports System.Data  
Imports System.Data.Common  
Imports System.Data.SqlClient  
Imports Telerik.Web.UI  
 
Namespace AppScheduler  
    Public MustInherit Class AppDbSchedulerProvider  
        Inherits DbSchedulerProviderBase  
        Public Overloads Overrides Function GetAppointments(ByVal owner As RadScheduler) As IEnumerable(Of Appointment)  
            Dim appointments As New List(Of Appointment)()  
 
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId] FROM [DbProvider_Classes]" 
 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim apt As New Appointment()  
                        apt.Owner = owner 
                        apt.ID = reader("ClassID")  
                        apt.Subject = Convert.ToString(reader("Subject"))  
                        apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader("Start")), DateTimeKind.Utc)  
                        apt.[End] = DateTime.SpecifyKind(Convert.ToDateTime(reader("End")), DateTimeKind.Utc)  
                        apt.RecurrenceRule = Convert.ToString(reader("RecurrenceRule"))  
                        If Not apt.RecurrenceParentID Is Nothing Then  
                            apt.RecurrenceParentID = reader("RecurrenceParentId")  
                        End If  
 
                        If apt.RecurrenceParentID <> Nothing Then  
                            apt.RecurrenceState = RecurrenceState.Exception  
                        ElseIf apt.RecurrenceRule <> String.Empty Then  
                            apt.RecurrenceState = RecurrenceState.Master  
                        End If  
 
                        LoadResources(apt)  
                        appointments.Add(apt)  
                    End While  
                End Using  
            End Using  
 
            Return appointments  
        End Function  
 
        'Public Overrides Sub Delete(ByVal owner As Telerik.Web.UI.RadScheduler, ByVal appointmentToDelete As Telerik.Web.UI.Appointment)  
        Public Overrides Sub Delete(ByVal owner As RadScheduler, ByVal appointmentToDelete As Appointment)  
            If Not PersistChanges Then  
                Return  
            End If  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                Using tran As DbTransaction = conn.BeginTransaction()  
                    cmd.Transaction = tran 
                    ClearClassStudents(appointmentToDelete.ID, cmd)  
                    cmd.Parameters.Clear()  
                    cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToDelete.ID))  
                    cmd.CommandText = "DELETE FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID" 
                    cmd.ExecuteNonQuery()  
                    tran.Commit()  
                End Using  
            End Using  
        End Sub  
 
        Private Sub FillClassStudents(ByVal appointment As Appointment, ByVal cmd As DbCommand, ByVal classId As Object)  
            For Each student As Resource In appointment.Resources.GetResourcesByType("Student")  
                cmd.Parameters.Clear()  
                cmd.Parameters.Add(CreateParameter("@ClassID", classId))  
                cmd.Parameters.Add(CreateParameter("@StudentID", student.Key))  
                cmd.CommandText = "INSERT INTO [DbProvider_ClassStudents] ([ClassID], [StudentID]) VALUES (@ClassID, @StudentID)" 
                cmd.ExecuteNonQuery()  
            Next  
        End Sub  
 
        Private Sub ClearClassStudents(ByVal classId As Object, ByVal cmd As DbCommand)  
            cmd.Parameters.Clear()  
            cmd.Parameters.Add(CreateParameter("@ClassID", classId))  
            cmd.CommandText = "DELETE FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID" 
            cmd.ExecuteNonQuery()  
        End Sub  
 
        Public Overrides Sub Insert(ByVal owner As RadScheduler, ByVal appointmentToInsert As Appointment)  
            If Not PersistChanges Then  
                Return  
            End If  
            Using conn As DbConnection = OpenConnection()  
                Using tran As DbTransaction = conn.BeginTransaction()  
                    Dim cmd As DbCommand = DbFactory.CreateCommand()  
                    cmd.Connection = conn 
                    cmd.Transaction = tran 
                    PopulateAppointmentParameters(cmd, appointmentToInsert)  
                    cmd.CommandText = " INSERT INTO [DbProvider_Classes]([Subject], [Start], [End], [TeacherID], [RecurrenceRule], [RecurrenceParentID]) VALUES (@Subject, @Start, @End, @TeacherID, @RecurrenceRule, @RecurrenceParentID)" 
                    If TypeOf DbFactory Is SqlClientFactory Then  
                        cmd.CommandText += Environment.NewLine + "SELECT SCOPE_IDENTITY()"  
                    Else  
                        cmd.ExecuteNonQuery()  
                        cmd.CommandText = "SELECT @@IDENTITY" 
                    End If  
                    Dim identity As Integer = Convert.ToInt32(cmd.ExecuteScalar())  
                    FillClassStudents(appointmentToInsert, cmd, identity)  
                    tran.Commit()  
                End Using  
            End Using  
        End Sub  
 
        Public Overrides Sub Update(ByVal owner As RadScheduler, ByVal appointmentToUpdate As Appointment)  
            If Not PersistChanges Then  
                Return  
            End If  
            Using conn As DbConnection = OpenConnection()  
                Using tran As DbTransaction = conn.BeginTransaction()  
                    Dim cmd As DbCommand = DbFactory.CreateCommand()  
                    cmd.Connection = conn 
                    cmd.Transaction = tran 
                    PopulateAppointmentParameters(cmd, appointmentToUpdate)  
                    cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToUpdate.ID))  
                    cmd.CommandText = "UPDATE [DbProvider_Classes] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [TeacherID] = @TeacherID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID WHERE [ClassID] = @ClassID" 
                    cmd.ExecuteNonQuery()  
                    ClearClassStudents(appointmentToUpdate.ID, cmd)  
                    FillClassStudents(appointmentToUpdate, cmd, appointmentToUpdate.ID)  
                    tran.Commit()  
                End Using  
            End Using  
        End Sub  
 
        Public Overloads Overrides Function GetResourceTypes(ByVal owner As RadScheduler) As IEnumerable(Of ResourceType)  
            Dim resourceTypes As ResourceType() = New ResourceType(2) {}  
            resourceTypes(0) = New ResourceType("Teacher", False)  
            resourceTypes(1) = New ResourceType("Student", True)  
            Return resourceTypes  
        End Function  
 
        Private Sub LoadResources(ByVal apt As Appointment)  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID))  
                cmd.CommandText = "SELECT [TeacherID] FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID AND [TeacherID] IS NOT NULL" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    If reader.Read() Then  
                        Dim teacher As Resource = apt.Owner.Resources.GetResource("Teacher", reader("TeacherID"))  
                        apt.Resources.Add(teacher)  
                    End If  
                End Using  
                cmd.Parameters.Clear()  
                cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID))  
                cmd.CommandText = "SELECT [StudentID] FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim student As Resource = apt.Owner.Resources.GetResource("Student", reader("StudentID"))  
                        apt.Resources.Add(student)  
                    End While  
                End Using  
            End Using  
        End Sub  
 
        Public Overloads Overrides Function GetResourcesByType(ByVal owner As RadScheduler, ByVal resourceType As String) As IEnumerable(Of Resource)  
            Select Case resourceType  
                Case "Teacher"  
                    Return GetTeachers()  
                Case "Student"  
                    Return GetStudents()  
                Case Else  
                    Throw New InvalidOperationException("Unknown resource type: resourceType")  
            End Select  
        End Function  
 
        Private Function GetTeachers() As IEnumerable(Of Resource)  
            Dim resources As New List(Of Resource)()  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [TeacherID], [Name], [Phone] FROM [DbProvider_Teachers]" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim res As New Resource()  
                        res.Type = "Teacher" 
                        res.Key = reader("TeacherID")  
                        res.Text = Convert.ToString(reader("Name"))  
                        res.Attributes("Phone") = Convert.ToString(reader("Phone"))  
                        resources.Add(res)  
                    End While  
                End Using  
            End Using  
            Return resources  
        End Function  
 
        Private Function GetStudents() As IEnumerable(Of Resource)  
            Dim resources As New List(Of Resource)()  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [StudentID], [Name] FROM [DbProvider_Students]" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim res As New Resource()  
                        res.Type = "Student" 
                        res.Key = reader("StudentID")  
                        res.Text = Convert.ToString(reader("Name"))  
                        resources.Add(res)  
                    End While  
                End Using  
            End Using  
            Return resources  
        End Function  
 
        Private Sub PopulateAppointmentParameters(ByVal cmd As DbCommand, ByVal apt As Appointment)  
            cmd.Parameters.Add(CreateParameter("@Subject", apt.Subject))  
            cmd.Parameters.Add(CreateParameter("@Start", apt.Start))  
            cmd.Parameters.Add(CreateParameter("@End", apt.[End]))  
            Dim teacher As Resource = apt.Resources.GetResourceByType("Teacher")  
            Dim teacherId As Object = Nothing 
            If teacher <> Nothing Then  
                teacherteacherId = teacher.Key  
            End If  
            cmd.Parameters.Add(CreateParameter("@TeacherID", teacherId))  
            Dim rrule As String = Nothing 
            If apt.RecurrenceRule <> String.Empty Then  
                rrule = apt.RecurrenceRule  
            End If  
            cmd.Parameters.Add(CreateParameter("@RecurrenceRule", rrule))  
            Dim parentId As Object = Nothing 
            If apt.RecurrenceParentID <> Nothing Then  
                parentId = apt.RecurrenceParentID  
            End If  
            cmd.Parameters.Add(CreateParameter("@RecurrenceParentId", parentId))  
        End Sub  
 
 
    End Class  
End Namespace 

Thanks

3 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 16 May 2008, 12:15 PM
Hello,

Currently your class is defined as abstract (MustInherit) and that is why you are receiving the error. You should remove MustInherit from the class definition.

Kind regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
jonnyO
Top achievements
Rank 1
answered on 17 May 2008, 08:04 PM
Good. Now I'm getting:

Server Error in '/Web' Application.


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadScheduler.BindResourcesFromProvider(IEnumerable`1 providedResourceTypes) +114
   Telerik.Web.UI.RadScheduler.PerformSelect() +113
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   Telerik.Web.UI.RadScheduler.EnsureDataBound() +48
   Telerik.Web.UI.RadScheduler.CreateChildControls(Boolean bindFromDataSource) +55
   Telerik.Web.UI.RadScheduler.CreateChildControls() +10
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041


With the following Provider code:

        Public Overloads Overrides Function GetResourceTypes(ByVal owner As RadScheduler) As IEnumerable(Of ResourceType)  
            Dim resourceTypes As ResourceType() = New ResourceType(3) {}  
            resourceTypes(0) = New ResourceType("EventUser", False)  
            resourceTypes(1) = New ResourceType("EventType", False)  
            resourceTypes(2) = New ResourceType("Attachments", True)  
            Return resourceTypes  
        End Function  
 
        Public Overloads Overrides Function GetResourcesByType(ByVal owner As RadScheduler, ByVal resourceType As String) As IEnumerable(Of Resource)  
            Select Case resourceType  
                Case "EventUser"  
                    Return GetUsers()  
                Case "EventType"  
                    Return GetTypes()  
                Case "Attachments"  
                    Return GetAttachments()  
                Case Else  
                    Throw New InvalidOperationException("Unknown resource type: resourceType")  
            End Select  
        End Function  
 
        Private Function GetUsers() As IEnumerable(Of Resource)  
            Dim resources As New List(Of Resource)()  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [SchedUserID], [SchedUserName] FROM [SchedAppProvider_User]" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim res As New Resource()  
                        res.Type = "EventUser" 
                        res.Key = reader("SchedUserID")  
                        res.Text = Convert.ToString(reader("SchedUserName"))  
                        'res.Attributes("Phone") = Convert.ToString(reader("Phone"))  
                        resources.Add(res)  
                    End While  
                End Using  
            End Using  
            Return resources  
        End Function  
 
        Private Function GetTypes() As IEnumerable(Of Resource)  
            Dim resources As New List(Of Resource)()  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [SchedTypeID], [SchedTypeLabel] FROM [SchedAppProvider_EventType]" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim res As New Resource()  
                        res.Type = "EventType" 
                        res.Key = reader("SchedTypeID")  
                        res.Text = Convert.ToString(reader("SchedTypeLabel"))  
                        'res.Attributes("Phone") = Convert.ToString(reader("Phone"))  
                        resources.Add(res)  
                    End While  
                End Using  
            End Using  
            Return resources  
        End Function  
 
        Private Function GetAttachments() As IEnumerable(Of Resource)  
            Dim resources As New List(Of Resource)()  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [SchedFileID], [SchedFileAttachmentLabel] FROM [SchedAppProvider_Attachment]" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim res As New Resource()  
                        res.Type = "Attachments" 
                        res.Key = reader("SchedFileID")  
                        res.Text = Convert.ToString(reader("SchedFileAttachmentLabel"))  
                        resources.Add(res)  
                    End While  
                End Using  
            End Using  
            Return resources  
        End Function  
 
        Private Overloads Sub LoadResources(ByVal apt As Appointment)  
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.Parameters.Add(CreateParameter("@SchedEventID", apt.ID))  
                cmd.CommandText = "SELECT [SchedUserID] FROM [SchedAppProvider_Events] WHERE [SchedEventID] = @SchedEventID AND [SchedUserID] IS NOT NULL" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    If reader.Read() Then  
                        Dim eventUser As Resource = apt.Owner.Resources.GetResource("EventUser", reader("SchedUserID"))  
                        apt.Resources.Add(eventUser)  
                    End If  
                End Using  
                cmd.Parameters.Clear()  
                cmd.Parameters.Add(CreateParameter("@SchedEventID", apt.ID))  
                cmd.CommandText = "SELECT [SchedFileID] FROM [SchedAppProvider_EventAttachments] WHERE [SchedEventID] = @SchedEventID" 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim attachments As Resource = apt.Owner.Resources.GetResource("Attachments", reader("SchedFileID"))  
                        apt.Resources.Add(attachments)  
                    End While  
                End Using  
            End Using  
        End Sub  
 
        Public Overloads Overrides Function GetAppointments(ByVal owner As RadScheduler) As IEnumerable(Of Appointment)  
            Dim appointments As New List(Of Appointment)()  
 
            Using conn As DbConnection = OpenConnection()  
                Dim cmd As DbCommand = DbFactory.CreateCommand()  
                cmd.Connection = conn 
                cmd.CommandText = "SELECT [SchedEventID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId] FROM [SchedAppProvider_Events]" 
 
                Using reader As DbDataReader = cmd.ExecuteReader()  
                    While reader.Read()  
                        Dim apt As New Appointment()  
                        apt.Owner = owner 
                        apt.ID = reader("SchedEventID")  
                        apt.Subject = Convert.ToString(reader("Subject"))  
                        apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader("Start")), DateTimeKind.Utc)  
                        apt.[End] = DateTime.SpecifyKind(Convert.ToDateTime(reader("End")), DateTimeKind.Utc)  
                        apt.RecurrenceRule = Convert.ToString(reader("RecurrenceRule"))  
                        If Not apt.RecurrenceParentID Is Nothing Then  
                            apt.RecurrenceParentID = reader("RecurrenceParentId")  
                        End If  
 
                        If apt.RecurrenceParentID <> Nothing Then  
                            apt.RecurrenceState = RecurrenceState.Exception  
                        ElseIf apt.RecurrenceRule <> String.Empty Then  
                            apt.RecurrenceState = RecurrenceState.Master  
                        End If  
 
                        LoadResources(apt)  
                        appointments.Add(apt)  
                    End While  
                End Using  
            End Using  
 
            Return appointments  
        End Function 

There is no current data in any of the SQl tables... is this the problem?  If so what's the best way to code for null?
0
jonnyO
Top achievements
Rank 1
answered on 18 May 2008, 04:27 AM
Thanks to another forum post I found via google "IEnumerable`1 providedResourceTypes)" search ... simple mistake "New ResourceType(3)" should have been 2

Thanks for your time
Tags
Scheduler
Asked by
jonnyO
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
jonnyO
Top achievements
Rank 1
Share this question
or