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

Defining Provider in Config File

3 Answers 88 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 02 Dec 2008, 06:18 PM
Hello,

I defined the custom scheduler provider (inheriting from DbSchedulerProviderBase) in the configuration file.  But the Provider property of the Scheduler control is null.  So do I have to do something to load the provider from the config file, or do I do something else?  I'm not sure if there is a method I have to call first, or if that is supposed to happen automatically.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 03 Dec 2008, 03:18 PM
Hello Brian,

Please, make sure you set the ProviderName property of RadScheduler. Here is how it is set in the online example which you referred to:

 <telerik:RadScheduler runat="server" ID="RadScheduler1" 
                    ProviderName="ReadOnlySchedulerData" ReadOnly="true" ...> 


Cheers,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
pucsoftware
Top achievements
Rank 1
answered on 17 Sep 2009, 07:39 PM
I am trying to use my inherited class I created based off the DbSchedulerProviderBase. I used the example to get this working and everything works when I bind it to the scheduler. However, what I need to do is open up a new window to a single appointment and allow users to export the item if they want. I was trying to manually create an Appointment item by creating a method in my scheduler provider class to just populate and return that single item. However, I can't instantiate an instance of the class. I can call the method but the OpenConnection() method fails with a value is null exception. The Scheduler component must be initializing the class properly but I can't see how I can do this outside using the component. Can this be done?
0
T. Tsonev
Telerik team
answered on 22 Sep 2009, 12:44 PM
Hi,

The DbSchedulerProviderBase class relies on the Initialize method to read the settings from the web.config file and this method indeed is not called in this scenario.

One option is to use the System.Web.Configuration.ProvidersHelper class to instantiate the provider:

using System.Web.Configuration;
using System.Configuration;
using Telerik.Web.UI;

RadSchedulerConfigurationSection section = (RadSchedulerConfigurationSection) WebConfigurationManager.GetSection("telerik.web.ui/radScheduler");
if (section != null)
{
    ProviderSettings providerSettings = section.AppointmentProviders["XmlSchedulerProvider"];
    MyProvider provider = (MyProvider) ProvidersHelper.InstantiateProvider(providerSettings, typeof(SchedulerProviderBase));
}


Another option is to create a new constructor that takes a connection string and initialize the DbFactory and ConnectionString properties in it:

public MyProvider(string connectionStringName)
{
    ConnectionStringSettings connectionSettings = ConfigurationManager.ConnectionStrings[connectionStringName];
    DbFactory = DbProviderFactories.GetFactory(connectionSettings.ProviderName);
    ConnectionString = connectionSettings.ConnectionString;
}

However, the first approach is more future-proof and I'd recommend using it instead.

Best wishes,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Scheduler
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Peter
Telerik team
pucsoftware
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or