Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 6 votes, 4.00 average. Display Modes
 
Unread ASP Free Forums Sponsor:
  #31  
Old May 9th, 2005, 12:09 AM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,394 lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)lewy User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 2 Days 4 h 40 m 31 sec
Reputation Power: 1629
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.

Reply With Quote
  #32  
Old May 9th, 2005, 10:23 AM
ASP-Hosting.ca ASP-Hosting.ca is offline
Need hosting? I can help.
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Posts: 826 ASP-Hosting.ca User rank is Private First Class (20 - 50 Reputation Level)ASP-Hosting.ca User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 17 h 50 m 37 sec
Reputation Power: 7
This thread is very useful as a guideline, what to do and what not to do

Reply With Quote
  #33  
Old May 9th, 2005, 01:28 PM
elijathegold's Avatar
elijathegold elijathegold is offline
Senior Fire Wizard
ASP Free God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2005
Location: Ashford, Kent. England
Posts: 5,651 elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 2 Months 2 Weeks 2 Days 4 h 30 m 19 sec
Reputation Power: 302
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!

Reply With Quote
  #34  
Old May 14th, 2005, 08:36 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
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.

Reply With Quote
  #35  
Old May 14th, 2005, 08:43 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
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.........

Reply With Quote
  #36  
Old May 14th, 2005, 09:05 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
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

Reply With Quote
  #37  
Old May 15th, 2005, 05:18 AM
elijathegold's Avatar
elijathegold elijathegold is offline
Senior Fire Wizard
ASP Free God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2005
Location: Ashford, Kent. England
Posts: 5,651 elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)elijathegold User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4Folding Points: 1980013 Folding Title: Super Ultimate Folder - Level 4
Time spent in forums: 2 Months 2 Weeks 2 Days 4 h 30 m 19 sec
Reputation Power: 302
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

Reply With Quote
  #38  
Old June 7th, 2005, 10:55 AM
dev5 dev5 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 494 dev5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 47 m 56 sec
Reputation Power: 6
This thread is very useful but can you all give more info on database structure and sql joins.

Reply With Quote
  #39  
Old June 7th, 2005, 11:06 AM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
Quote:
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

Reply With Quote
  #40  
Old June 7th, 2005, 12:42 PM
dev5 dev5 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 494 dev5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 47 m 56 sec
Reputation Power: 6
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...

Reply With Quote
  #41  
Old June 7th, 2005, 01:45 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
Quote:
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

Reply With Quote
  #42  
Old June 9th, 2005, 05:31 PM
werD's Avatar
werD werD is offline
Certified Abuser
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2005
Location: Line 73 ---^
Posts: 1,050 werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)werD User rank is First Lieutenant (10000 - 20000 Reputation Level)  Folding Points: 20652 Folding Title: Starter FolderFolding Points: 20652 Folding Title: Starter Folder
Time spent in forums: 1 Week 4 Days 21 h 52 m 57 sec
Reputation Power: 128
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

Quote:
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/d...tml/asptips.asp
asp A-Z
__________________
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

Last edited by werD : June 27th, 2005 at 03:27 PM.

Reply With Quote
  #43  
Old July 15th, 2005, 09:19 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
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

Reply With Quote
  #44  
Old July 15th, 2005, 09:23 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
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.

Reply With Quote
  #45  
Old July 15th, 2005, 09:29 PM
bslintx's Avatar
bslintx bslintx is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Location: United States
Posts: 1,814 bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level)bslintx User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 17 h 26 m 7 sec
Reputation Power: 8
Send a message via Yahoo to bslintx
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

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Best Practices : ASP Coding, SQL Statements, and Database Structuring


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek