Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...DB Connections Within DNN FrameworkDB Connections Within DNN Framework
Previous
 
Next
New Post
1/27/2009 4:51 PM
 

I am in the process of building a module with VB in VS2008.

My goal is to have the application display a title (as a button), and display details (within a panel) when the button is clicked, via a VB If statement.
I am using a datalist to accomplish this; I need Add/Change/Delete capability.
 
My issue is this: I am not sure what I need to do to instruct the module on how to connect to the DataSource.
Ordinarily, I'd do something like this:
using (SqlConnection odsCharge = new SqlConnection(ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString))
But as it is already defined in the web.config file, I don't think that the connection works that way within the DNN framework.
 
Any suggestions?

 

 
New Post
1/28/2009 12:48 AM
 

 Hey Chronofied,

I'd suggest reading up on the articles found here under "Connect your module to the Database"

http://adefwebserver.com/dotnetnukehelp/

Take care,

Ian


Software Engineer
Co-Founder, dnnGallery
Stack Overflow: Ian Robinson
Twitter: @irobinson
Linked In: Ian Robinson
 
New Post
1/28/2009 5:34 PM
 

Ian, thanks for the reply...

Unfortunately, though everybody seems to think that ADef is the answer for everything, it does not help me in this.  I've read over half the articles on that site (including all of the most recent ones) and re-read that particular article again.  It suffers from the same problems as other tutorials on the site, and from the same problems that I have with the module development guides.  That is not to say they have been unhelpful; quite the contrary.  I have only gotten as far as I have largely because of the information on Adef.  One issue I have, as a rather inexperienced developer, is that I feel like there are assumptions made about the knowledge level of the reader.  The other major issue, which I feel is a direct result of that, is that there is a lack of specificity.  For example, in the Survey module that is used throughout, there are two files, called DNN_Survey.dnn & DNN_Survey.dnn.config.  What I have read in other places leads me to believe that these are DAL object files, important to the Database connection.  I think there is a good chance that I'm wrong, however, as he just calls them "Text Files" and doesn't explain their purpose.  I would also like to know what the SQL Script files do, rather than just blindly copying and pasting them.  A copy and paste operation is not a tutorial designed to instruct and educate, but merely to replicate.  So, due to a lack of knowledge (on my part, I'll be the first one to admit) I am not getting the information I need from ADef.

If anybody can give me more specifc information about connecting to a database, in particular the way it works within the DNN Framework, what files are needed (and more importantly, why they are needed), etc.  I would be very appreciative.

Thanks.

 

 
New Post
1/29/2009 1:13 AM
Accepted Answer 

Hey Chronofied,

When you create a module you can package and install it into a DNN site (I'm sure you know this already). I like to call this "registering" the module with your DotNetNuke site. When you register the module there is a file that describes the module's files so that DNN knows what to do with them (run sql scripts, move user controls to the right folder, move assemblies to the right folder, etc...). This is the .dnn file (commonly referred to as a manifest file). The .dnn.config file is actually the same file - it is renamed with .config after installation. I've always assumed that this is because IIS will never serve a .config file - so it's just kind of "archiving" it as it is not needed after installation.

As for the SQL scripts are just used to create database objects (stored procedures, views, or tables) that your custom module will use.

[Disclaimer, this is not the only way to do it, and I may have left things out, so please ask if you have any questions]

The "DotNetNuke best practice" for database access is as follows:

The user control and business objects are pretty self explanatory (and aren't "unique" to DNN). When a business object needs to retrieve information from the data store, you'll write some code like this: DataReader myReader = DataProvider.Instance().GetMyData(parameter1, parameter2); and will create an instance of the data provider dynamically (using reflection) and then call the appropriate method off of the concrete data provider.

Relevent sections of the web.config:

Connection String

 <connectionStrings>

    <add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke_2;uid=dnn2_user;pwd=dnn;" providerName="System.Data.SqlClient"    />

  </connectionStrings>

Data

<data defaultProvider="SqlDataProvider">

        <providers>

        <clear      />

        <add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="dnn_" databaseOwner="dbo"      />

        </providers>

</data>

 

Abstract Data Provider

knows how to create an instance of the concrete data provider based on the informaiton in the web.config. Defines the methods that the concrete data provider must implement (but does not implement them itself).

static readonly DataProvider Provider = (DataProvider)Reflection.CreateObject("data", "Engage.Dnn.Module", "");
//"data" above refers to the section of the web.config

SqlDataProvider  knows how to actually connect to the database (again, based on the database related web.config entries) and actually implements the methods in the abstract data provider.

Here is the constructor for a SqlDataProvider:

 public SqlDataProvider()

        {

            //Read the configuration specific information for this provider

            Provider objProvider = (Provider)_providerConfiguration.Providers[_providerConfiguration.DefaultProvider];


            //Read the attributes for this provider

            //Get Connection string from web.config

            _connectionString = Config.GetConnectionString();


            if (_connectionString.Length == 0)

            {

                //Use connection string specified in provider

                _connectionString = objProvider.Attributes["connectionString"];

            }


            _providerPath = objProvider.Attributes["providerPath"];


            _objectQualifier = objProvider.Attributes["objectQualifier"];


            if (!String.IsNullOrEmpty(_objectQualifier) && _objectQualifier.EndsWith("_", StringComparison.Ordinal) == false)

            {

                _objectQualifier += "_";

            }


            _databaseOwner = objProvider.Attributes["databaseOwner"];

            if (!String.IsNullOrEmpty(_databaseOwner) && _databaseOwner.EndsWith(".", StringComparison.OrdinalIgnoreCase) == false)

            {

                _databaseOwner += ".";

            }

        }

Application Blocks 

is the Microsoft data access library used by the SQL Data Provider and distributed with DotNetNuke.

CBO (Custom Business Objects)

is a DotNetNuke utility for populating a custom business object from a DataReader. The default implementation uses reflection to inspect the object and matches (public) properties with column names in the DataReader. There is an interface that your business object can implement (IHydratable) that allows you to provide an alternative implementation than the default "black box" reflection method. Here is more info on CBO:


Software Engineer
Co-Founder, dnnGallery
Stack Overflow: Ian Robinson
Twitter: @irobinson
Linked In: Ian Robinson
 
New Post
1/29/2009 9:21 AM
 

Ian,

That was awesome.  I'd say that about 35% of that was totally new information to me, and very helpful in "connecting the dots" so to speak.
I'm sure I will have additional questions, as there are still a few peices missing in my understanding, but this has helped me get much father along.
Now I'm going to go and see if I can get back inside my module and make more sense of it.
I'd just like to reiterate how much I appreciate this kind of response; it's fantastically helpful.

Thanks.

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...DB Connections Within DNN FrameworkDB Connections Within DNN Framework


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out