Creating DotNetNuke SqlDataProvider Files Using SSMS 

One of the biggest failure points I see with third-party DotNetNuke modules, including some of my first released modules were failures due to the lack of support for ObjectQualifier or DatabaseOwner values within the SqlDataProvider files.  Although the process to add support for these two tokens is easy to add, it is very hard for those of us that like to test our database structures outside of DotNetNuke before we actually commit to building our modules.  Thankfully, with a bit of research, I have found a way to build SQL Scripts for DotNetNuke using SQL Server Management Studio (SSMS) in a normal fashion and using a simple find/replace operation to bring everything into compliance with DotNetNuke integration.  This post will explore the method that I use to accomplish this.

Setup

Depending on your exact scripting needs you might want to configure the SSMS scripting options to "script drops" before the creates of stored procedures, allowing you to do a complete scripting run out of the box.  You can also work with various options to tailor the generated SQL Scripts to meet your needs.  Otherwise no special setup is needed.

Writing the Scripts

The best part about the way that I write my SQL scripts is that only slight modifications are needed to write the scripts in a manner that can be executed on any database directly from SSMS and then converted easily into DotNetNuke compliant scripts.  The only change that you must make is that ALL objects must be qualified with a database owner, and the object name must be surrounded in []'s.  So a stored procedure creation must be similar to "CREATE PROCEDURE dbo.[MyPrefix_InsertMyData]", this rule applies to all objects, including from clauses and joins within the stored procedures.

By doing this you have a consistent form to your scripts that still complies with the needs of a default SQL Server implementation but also allows for a very simple find and replace to prepare objects for DotNetNuke integration.  Once you have written the scripts, feel free to run them and insert the objects into a test database, this way you can truly validate that your syntax is correct and perform any other validations needed.

Creating the DotNetNuke Scripts

Once you have successfully created the scripts and validated that they are correct you can use a simple find/replace option to make the scripts DNN compliant.  You have two options when it comes to performing this step.  The first is to simply use the SQL scripts that you executed, however, those might not yet have the drop statements needed to ensure that scripts are re-usable.  The second option is to use the "Script Object As" options within SSMS to have it script the Create or Alter statements for you.  The key is to get to a point where all scripts, in their current form are inside a single document.

Once the items are in a single document simply use find/replace.  Search for "dbo.[" without the quotes and specify "dbo.]" without the quotes as the replace with text.  This will sub out the hard coded database owner and will supply the DotNetNuke tokens, making the script fully functional within the DotNetNuke module installation environment.

Conclusion

I hope this posting has helped someone with the creation of DotNetNuke module scripts.  Although I do not like the use of an ObjectQualifier as a custom module developer for DotNetNuke it is important to follow the standards set forth to ensure that modules function in a manner that users expect.

Feel free to share your comments below.

Posted by Mitchel on Monday, January 26, 2009
 

Comments

In the past I have been using SMSS to create the stored procedures as you explain. However, when doing this, I cannot run local DNN installs since it does not close the connection to the database as expected. I need to manually terminate all the sql process and restart them before running. Anyone else?

By Dario Rossa on Tuesday, January 27, 2009 at 5:58 AM

I have never had that issue....now typically when generating scripts I am working on a different DB than my DNN test one...but even when I have that open I don't loose connection.

Which version of SQL Server are you using?

By mitchel.sellers@gmail.com on Tuesday, January 27, 2009 at 8:44 AM

Good post. One of the things I routinely do to minimize the sheer number of replacements is to judiciously use table aliases in my procs.

For instance when joining a couple tables like modules and tabmodules I'll use something like this:

dbo.myqualifier_Modules M inner join dbo.myqualifier_TabModules TM ON M.ModuleId = TM.ModuleId

I also find it improves the readability of the procs I write as well.

By Richard Edwards on Friday, March 13, 2009 at 9:58 AM

Thanks, great post. Would be interesting to know how the {objectqualifier} token is intended to be used though, as the VS starter kit inserts it and a hard-coded MyCompany_ prefix on all object names. I assume that the starter kit is misleading, that the objectqualifier is intended for company and the hard-coded prefix should read ModuleName_

By Paul Taylor on Monday, May 31, 2010 at 2:14 AM

Hi Mitchel,
I hope you will be doing well. I usually refer your books on DNN but this time I'm here directly.
Actually, I found dataset as the fastest way to add database feature into any application and for all of my work for dnn is using a separate class library containing datasets and hard coded database connection string. The way I did it, is notable to transfer my module package to anyone because each time i request for connection string and build my class library for them.
How can i fix this now?

By babuilyas on Tuesday, February 01, 2011 at 4:31 AM

You can modify your code to grab the connection string from the web.config file just like a regular module would do. I don't have the code handy, but you could review the template code to see how it is done.

By mitchel.sellers@gmail.com on Tuesday, February 01, 2011 at 9:39 PM

I realize this is an old thread, but I recently came across a related problem and wanted to share this with others.

Years ago, SQL licensing was very costly so web hosts would share a common SQL Server with multiple users for a reduced fee, allowing a single database for multiple applications. Originally the objectQualifier allowed multiple DNN applications to share a single common database.

Things have changed since then (SQL Express) and although it was a unique solution from DNN at the time, I believe it has caused, and continues to cause far more damage, time and negativity than it is worth. Unless I am missing something the {objectQualifer} and dbo. should be deprecated immediately if not sooner. (Please feel free to tell me otherwise.)

To demonstrate how bad this little menace is, paste the following script via Host|SQL and examine the results. Note that EVERYTHING reported will NOT work in a shared database (which was precisely what an objectQualifer is for!)

SELECT o.name FROM sys.objects as o inner join sys.schemas as s on o.schema_id = s.schema_id where o.name not like '%%' and o.name not like '%aspnet_%' and not s.name= 'sys' order by o.name

This should not be a module developer problem. It should not prevent use of LINQ to SQL or Entity Framework (a very special thanks to Braydon Hayes for solving those ones). In fact, the objectQualifier is probably the single most despicable task of DNN module development. How many innovative and novel ideas and modules have been shelved because of the this?

The DNN core code is a mess from this requirement. The DAL (data access layer) for any DNN module is a complete joke with curly brace delimiters and quoted strings throughout. How many times you manually edited a .SqlDataProvider file just to get it to work?

This should be top priority for DNN Corp. as well as all module developers. Just make a note in your release notes to indicate that your module does not support the objectQualifier. I dream of the day when we can use SMSS and DNN script interchangeably, along with LINQ, EF and whatever else comes along.


Goodbye and dbo., and good riddance!

By Dwayne J. Baldwin on Thursday, February 10, 2011 at 8:06 PM

Dwayne J. Baldwin raises a big question. Point is logical, lets see what DNN Core team says about this. I know DNN 5.6 still requires ObjectQuntifier and databaseOwner in sql scripts.

By babuilyas on Thursday, February 10, 2011 at 10:24 PM

The objectQualifier and databaseOwner junk makes module development way more complicated than it needs to be. It makes it exceedingly difficult to leverage Entity Framework in modules. I'd love to be able to make use of the new Code First feature that is about to be released in the upcoming Entity Framework 4.1. However, I just don't see how it's possible, at least not if I want to distribute a module, since the names of the tables and other database objects are likely to be different depending on how the end user has their DNN instance configured.

Unfortunately, given the need to maintain at least some level of backward compatibility with legacy modules, I really don't see how the DNN core team could eliminate these tokens.

By Bryan on Monday, March 07, 2011 at 2:27 PM

I just Googled "smss" and you are the 10th result and the only result that shows a photo. Congrats!

By Jamie Llewellyn on Friday, April 29, 2011 at 7:06 PM

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above:

Content provided in this blog is provided "AS-IS" and the information should be used at your own discretion.  The thoughts and opinions expressed are the personal thoughts of Mitchel Sellers and do not reflect the opinions of his employer.

Friend of RedGate

www.datasprings.com - DotNetNuke Modules ICG Hosting

Click here for advertising information.

Content in this blog is copyright protected.  Re-publishing on other websites is allowed as long as proper credit and backlink to the article is provided.  Any other re-publishing or distribution of this content is prohibited without written permission from Mitchel Sellers.