More in this section

Forums / Developing with Sitefinity / Data Access for Custom Module Data Access for Custom Module

2 posts, 0 answered
  1. Benjamin
    Benjamin avatar
    1 posts
    18 May 2009
    09 Jun 2009
    Link to this post
    I'm creating a custom module (pluggable) and decided to use for data access. I followed the instructions in your developer documentation for creating a data access project. The documentation says that will automatically read the connection string used for Sitefinity, yet it appears that the data connection still needs to be initialized. Without doing any initialization I receive the following exception when trying to load data from the module:

    The database class Foo.Data.TestData has not been registered. Use DataConnection.Initialize or DataConnection.RegisterAssembly to register an assembly.

    I added code to initialize the DataConnection in the initialization of my module, but now I receive the following exception:

    There is no data provider for class Foo.Data.TestData. Did you forget to connect?

    Could you give an example of exactly where and how the DataConnection needs to be initialized in order for to use the Sitefinity database for a custom module. Also, is there any additional code that needs to be added to ensure that automatically upgrades the database schema to match the data classes?

  2. Vlad
    Vlad avatar
    498 posts
    19 Jun 2017
    12 Jun 2009
    Link to this post
    Hi Benjamin,

    Basically, in the Initialize method of you module data provider you should do the following:
            public override void Initialize(string name, NameValueCollection config) 
                // upgrades the database with Nolics 
                if (string.IsNullOrEmpty(name)) 
                    name = "DefaultContactsProvider"
                if (string.IsNullOrEmpty(config["description"])) 
                    config.Add("description", Messages.DefaultProviderDescription); 
       = ApplicationHelper.GetApplication(config); 
                Assembly assembly = Assembly.GetExecutingAssembly(); 
                DataConnection.Initialize(false, assembly); 
                this.odbProvider = NolicsHelper.SetConnection(config["connectionStringName"], name); 
                bool upgrade = false
                base.Initialize(name, config); 

    You can also review the following blog post:
    Sample pluggable module: Contacts pluggable module.

    Do let us know if you need further assistance.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered