More in this section

Forums / Developing with Sitefinity / Nolics.net Data Access for Custom Module

Nolics.net Data Access for Custom Module

2 posts, 0 answered
  1. Benjamin
    Benjamin avatar
    1 posts
    Registered:
    18 May 2009
    09 Jun 2009
    Link to this post
    I'm creating a custom module (pluggable) and decided to use Nolics.net for data access. I followed the instructions in your developer documentation for creating a Nolics.net data access project. The documentation says that Nolics.net 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 Nolics.net to use the Sitefinity database for a custom module. Also, is there any additional code that needs to be added to ensure that Nolics.net automatically upgrades the database schema to match the data classes?

    Thanks!
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    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); 
     
                this.app = ApplicationHelper.GetApplication(config); 
     
                Assembly assembly = Assembly.GetExecutingAssembly(); 
                DataConnection.Initialize(false, assembly); 
     
                this.odbProvider = NolicsHelper.SetConnection(config["connectionStringName"], name); 
                 
                bool upgrade = false
                 
                this.odbProvider.Upgrade(); 
                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.

    Regards,
    Vlad
    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