[Dnn module development] how to write the module database installation script

Source: Internet
Author: User
Tags sql server query dnn

Compiling the dotnetnuke (dnn) module-related database installation/uninstallation scripts is an important part of module development. DnnProgramThe tables and stored procedures related to the module are automatically installed or uninstalled Based on the script related to the module.

The database installation script of the module in dnn is generally named version number. The specific data access provider name (for example, the corresponding sqlserver installation file can be 01.00.00.sqldataprovider ). When uploading a new module, the module installer of dnn executes the database script in version order according to the database script list listed in the dnn file. For upgrade and installation, only the database installation script later than the previous version of the module is executed. Therefore, you must remember this when writing the next version of the database installation script: Modify it on the basis of the original version, rather than rewrite it all. For example, if you only add a stored procedure to a module in the next version, the database script of this version only needs to includeCodeNo need to overwrite all objects. Pay attention to the consistency between the module version and the database script version.

The database uninstall script of the module in dnn is generally named as Uninstall. The specific data access provider name (for example, the uninstall. sqldataprovider file corresponding to sqlserver can be used ). When deleting a module, dnn deletes the table and stored procedures related to the module based on the content of the file.

The script can be written as follows (the SQL Server database is used as an example ):
1. Create tables and stored procedures in the database.
2. You can use the SQL Server Query analyzer to generate a script for creating or removing tables and stored procedures. The specific practices are as follows:

3. Copy the scripts of these objects to a file, and add the {databaseowner} {objectqualifier} prefix before the table and stored procedure object names; add the {objectqualifier} prefix to the primary/foreign key name, for example, PK {objectqualifier} _ clinks and FK _ {objectqualifier} clinks_modules.
For the meaning and purpose of {databaseowner} {objectqualifier}, see: http://www.cnblogs.com/csdn/archive/2004/11/30/71118.html
4. Name the files according to the naming rules of the database installation/uninstall script.
5. For more information, see install or Uninstall a script file in the database of an existing module.
6. It seems that a template can also be used to write a stored procedure, but it seems that it is not very useful. If you are interested, you can check it out:

A noteworthy problem:
The SQL Server database installation/uninstallation script is executed through the executescript method in the sqldataprovider class. This method contains the following sentence: "dim delimiter as string =" go "& controlchars. CRLF ", that is, to separate each SQL statement that can be executed in an SQL script using the" go + carriage return linefeed. Use split to separate each statement into an array and execute each SQL statement cyclically. In this way, when writing the database installation/uninstall script, you must note that the "go + carriage return" line break is added to the end of each statement, especially the "carriage return line break" in the last sentence. Otherwise, either the last sentence cannot be executed or an error is reported.

There is another noteworthy problem:
The script file for database installation/uninstallation must be saved in UTF-8 format; otherwise, an error may occur.

Related content:
Hierarchy of dnn modules: http://www.cnblogs.com/esshs/archive/2005/07/27/201190.html
About module File structure: http://www.cnblogs.com/esshs/archive/2005/07/21/197198.html
About dnn file structure: http://www.cnblogs.com/esshs/archive/2005/07/26/200154.html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.