#31
  1. Alter Ego Wizard
    ASP Genius (4000 - 4499 posts)

    Join Date
    Jun 2004
    Location
    Edinburg Tx
    Posts
    4,401
    Rep Power
    1660
    Very nice thread indeed.
    Good job bslintx, this thread is very informative for newbies and some of us who have a bit more time making asp code. Thanks for the refresher.
    I'd give you points but system won't allow it, as soon as I can, they're yours.
  2. #32
  3. No Profile Picture
    Need hosting? I can help.
    ASP Adventurer (500 - 999 posts)

    Join Date
    Sep 2003
    Posts
    826
    Rep Power
    15
    This thread is very useful as a guideline, what to do and what not to do
  4. #33
  5. Senior Fire Wizard
    ASP Mastermind (5000+ posts)

    Join Date
    Feb 2005
    Location
    Ashford, Kent. England
    Posts
    5,651
    Rep Power
    317
    Comments are your friend. They can also be your enemy.

    So not only comment your code, comment it properly. Don't say "what" - that should be apparent from the code. Say "why" - not always so obvious more than 6 months down the line.

    consider the following, harmless looking code

    No Comment
    Code:
       ...
       a = a + 1
       ...
    Bad Comment: (I used to work with a programmer who did comments like this all the time)
    Code:
        ...
       ' Add 1 to a
       a = a + 1
        ...

    Better Comment:
    Code:
       ...
       '  Keep track if how many items have been added to the collection
       a = a + 1
        ...
    Even Better Comment
    Code:
        ...
     '  This will be used to limit a paging algorithm found in function myPageSet.
      '   It is a count of how many items added.
       a = a + 1
        ...
    Ok this is a trivial example, but in a system with 1000s of lines of code thy make a huge difference.

    Elija

    Comments on this post

    • bslintx agrees : very nice comment layout example!
  6. #34
  7. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16

    Avoid Redundant Code


    Avoid Redundant Code

    Redundant code refers to code blocks that are identical or nearly identical in different parts of an application. Redundant code adds processing load on the server side because an ASP page must be compiled each time that it is requested from the server. And the more code there is to compile, the more processing time is used. Also, redundant code is hard to debug and maintain because such blocks of code generally must be edited separately each time a change is made (even though they all perform the same basic process).

    Subs and Functions

    If you can identify identical or similar code blocks in your application, consider converting these code blocks to Subs or Functions. Subs and Functions can take parameters so it doesn't matter if the code blocks do similar things; you can create parameters that enable the functionality of Subs and Functions to be extended. In addition, by combining similar code blocks into Subs and Functions, debugging and extending the code can be done more easily. Rather than having to find all the similar code blocks and edit each separately, only one Sub or Function needs to be edited.
  8. #35
  9. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16

    Objectives of Good Relational Database Design:


    Objectives of Good Relational Database Design:

    There are many distinct objectives that you must achieve in order to design a good, sound, structured database. You can avoid many of the problems you may encounter by keeping the following objectives in mind and constantly focus on these whilst designing your database.

    • The database supports both required and ad hoc (unplanned) information retrieval. The database must be designed to store the data necessary to support information requirements defined during the design process and any possible ad hoc queries that may be posed by the users.
    • The tables are constructed properly and efficiently. Each table in the database must represent a single subject only and should be composed of relatively distinct fields which keep redundant data to an absolute minimum and should be identified throughout the database by a field with unique values.
    • Data integrity is imposed at the field, table and relationship levels. These levels of integrity help guarantee that the data structures and their values will be valid and as accurate as possible at all times.
    • The database should support business rules relevant to the organization it is designed for. The data must provide accurate information that is always meaningful to the business.
    • The database should lend itself to future growth and development. The database structure should be easily modifiable and expendable as the information requirements of the business continue to change and grow.
    You may find it difficult at times to fulfill all of these objectives, but you'll certainly be pleased with your final database design structure once you've met them.

    Benefits of Good Database Design:

    The time that you invest in designing a sound, well strucuted database is time well spent. Good database design saves you time in the long run because you do not have to spend time constantly revamping a quickly and poorly designed structure. You gain the following benefits when you apply good design techniques:

    • The database structure is easy to modify and maintain. Modifications you make to a table or field will not adversely affect other tables or fields in the database.
    • The data is easy to modify. Changes that you make to the value of a given field will not adversely affect the values of other fields within the table. Furthermore, a well-designed database keeps duplicate fields to an absolute minimum, so you typically modify a particular data value in one field only.
    • Information is easy to retrieve. You should be able to create queries easily due to well constructed tables and the relationships between them are correctly established.
    • End-User applications are easy to develop and build. You can spend more time on programming and addressing the data manipulation tasks at hand, instead of working around the inevitable problems that will arise when you work with a poorly designed database

    MUCH MORE TO COME.........
  10. #36
  11. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16

    Naming Tables and Fields


    Naming Tables and Fields

    Once we've reached this point, let's establish our table and field names. Names for all database elements should be:

    • Unique
    • Clear, meaningful, unambiguous
    • Short
    Some restrictions for naming tables:

    • No acronyms or abbreviations
    • No proper names or words which unduly limit the data which can be entered
    • Should not imply more than one subject
    • Should be plural
    And for naming fields:

    • No acronyms
    • Use abbreviations only if clear and meaningful
    • Should not imply more than one subject
    • Should be singular
    You'll probably see some duplicate field names, such as "Name" in both the "Companies" and "People" tables. Let's make them unique across the database. You might choose "ContactName" and "CompanyName" but whatever you use, stick to the guidelines above, and be consistent
  12. #37
  13. Senior Fire Wizard
    ASP Mastermind (5000+ posts)

    Join Date
    Feb 2005
    Location
    Ashford, Kent. England
    Posts
    5,651
    Rep Power
    317
    Good posts by bslintx but would just like to add:

    Subs and functions can not only be used to remove redundant code, that can also be used to simplify code.

    Move functional blocks of code to subroutines and functions and give them meaningful names. This will turn your main program logic into an overview of the program and clarifies the program flow, makes it easier to debug and change.

    Elija
  14. #38
  15. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jan 2004
    Posts
    494
    Rep Power
    14
    This thread is very useful but can you all give more info on database structure and sql joins.
  16. #39
  17. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16
    Originally Posted by dev5
    This thread is very useful but can you all give more info on database structure and sql joins.

    appreciate the response dev...would be great to share your knowledge on this subject too...join on in...again thanks!
    Please give respect to those that helped solve an issue by clicking on the icon
  18. #40
  19. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Jan 2004
    Posts
    494
    Rep Power
    14
    I am still in learning process and trying to learn as much as possible. All your great thoughts are food for thought for me. thanks again.

    Comments on this post

    • Shadow Wizard agrees : lol I liked the food part... ;)
  20. #41
  21. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16
    Originally Posted by dev5
    I am still in learning process and trying to learn as much as possible. All your great thoughts are food for thought for me. thanks again.

    no problem dev....i'll work on that soon...thanks for the insight
  22. #42
  23. Certified Abuser
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Jan 2005
    Location
    Line 73 ---^
    Posts
    1,050
    Rep Power
    137
    Use queries as their intended... Their are many different options for your query rather than.. Select * From Table

    Here is a good link with some query examples and some comments about them...


    http://www.l-and-b.dk/asp/sql.asp

    Access Queries


    btw Good Thought bslintx

    Originally Posted by werD
    Hey all i just wanted to throw this link out here. This is a really good link from Microsoft explaining some good practices to clean up your code and help out your user experience!
    http://msdn.microsoft.com/library/de...ml/asptips.asp
    asp A-Z
    Last edited by werD; June 27th, 2005 at 03:27 PM.
    werD, MCSD .Net
    <% ASP,.NET App Development %>

    Really Help People with Real Diseases... And Get a Cool Blue Flower!

    If a post has helped you please use the scales... we all need bigger heads
  24. #43
  25. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16

    Do Not Cache Database Connections in the Application or Session Objects


    Caching ADO Connections is usually a bad strategy. If one Connection object is stored in the Application object and used on all pages, then all pages will contend for use of this connection. If the Connection object is stored in the ASP Session object, then a database connection will be created for every user. This defeats the benefits of connection pooling and puts unnecessarily high stress on both the Web server and the database.

    Instead of caching database connections, create and destroy ADO objects on every ASP page that uses ADO. This is efficient because IIS has database connection pooling built in. More accurately, IIS automatically enables OLEDB and ODBC connection pooling. This ensures that creating and destroying connections on each page will be efficient.

    Since connected recordsets store a reference to a database connection, it follows that you should not cache connected recordsets in the Application or Session objects. However, you can safely cache disconnected recordsets, which don't hold a reference to their data connection. To disconnect a recordset, take the following two steps:

    Code:
     Set rs = Server.CreateObject("ADODB.RecordSet")
        rs.CursorLocation = adUseClient  ' step 1
    
        ' Populate the recordset with data
        rs.Open strQuery, strProv
    
        ' Now disconnect the recordset from the data provider and data source
        rs.ActiveConnection = Nothing    ' step 2
  26. #44
  27. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16

    Release the database connection to the connection pool as quickly as possible




    When you are done using a recordset, say after painting a table with its data, release it immediately, rather than waiting until the end of the page. Setting your VBScript variable to Nothing is a best practice. Don't let the recordset simply fall out of scope. Also, release any related Command or Connection objects. (Don't forget to call Close() on recordsets or Connections before setting them = Nothing.) This shortens the time span in which the database must juggle resources for you, and releases the database connection to the connection pool as quickly as possible.
    Last edited by bslintx; August 9th, 2005 at 10:34 AM.
  28. #45
  29. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Apr 2004
    Location
    United States
    Posts
    1,814
    Rep Power
    16

    Use Option Explicit to Speed up Processing


    Use Option Explicit in your .asp files. This directive placed at the top of the .asp file forces the developer to declare all variables that will be used. Many programmers consider this helpful in debugging applications, as it avoids the chance of mistyping a variable name and inadvertently creating new variables (for example, MyXLMString=... instead of MyXMLString=).

    Perhaps more important, it turns out that declared variables are faster than undeclared variables. Under the covers, the scripting run time references undeclared variables by name, every time they are used. Declared variables, on the other hand, are assigned an ordinal, either at compile time or run time. Subsequently, declared variables are referenced by this ordinal. Since Option Explicit forces variable declaration, it insures that all variables are declared and thus will be accessed quickly

Similar Threads

  1. ASP and SQL
    By nofriends in forum Code Bank
    Replies: 12
    Last Post: October 14th, 2008, 02:56 PM
  2. Exception Handling
    By kirandayalin in forum ASP Development
    Replies: 14
    Last Post: April 21st, 2005, 02:16 PM
  3. combine SQL statements
    By leuvenaar in forum ASP Development
    Replies: 3
    Last Post: April 19th, 2005, 07:59 AM
  4. Replies: 3
    Last Post: January 14th, 2005, 03:38 PM
  5. Replies: 2
    Last Post: February 11th, 2004, 03:51 PM

IMN logo majestic logo threadwatch logo seochat tools logo