ASP
  Home arrow ASP arrow Page 3 - Two Ways To Connect To SQL Server 2000 Via...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Two Ways To Connect To SQL Server 2000 Via ASP
By: Joe O'Donnell
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 162
    2002-01-13

    Table of Contents:
  • Two Ways To Connect To SQL Server 2000 Via ASP
  • Using system DSN's
  • Using system DSN's (contd.)
  • Using an OLEDB connection string
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Two Ways To Connect To SQL Server 2000 Via ASP - Using system DSN's (contd.)


    (Page 3 of 5 )

    Click on the next button to continue with the wizard. If you have already designed a new database or just prefer not to use the master database once you're actually connected to SQL Server (highly recommended: the master database contains several important extended stored procedures and tables that should be treated with care), then change the default database name from "master" to "Northwind", for example.

    The "Attach Database Filename" text box allows you to attach a database file to your DSN. We won't use this method in our example. Make sure the "Use ANSI quoted identifiers" and "Use ANSI nulls, paddings and warnings" check boxes are checked. They tell SQL server to make sure that in any SQL queries, identifiers containing special characters or match keywords must be enclosed in identifier quote characters. Click the next button to move onto the last tab of the system DSN wizard.

    All of the options on this tab can be left as is, accept one. If you have specialized currency symbols, dates or regional settings, then make sure that the "Use regional settings when outputting currency, numbers, dates and times" check box is checked. This will save you the effort of having to convert dates and other fields to your countries local format every time they are used.

    That's all we need to do to create a system DSN. Click on the finish button. The "Verify DSN Settings" dialog appears. If you'd like to test our newly created system DSN, then click on the "Test Data Source…" button. If not, simply click OK.

    Testing our new system DSN

    To connect to your database using a system DSN, it's simply a matter of instantiating a new ADO connection object from within your ASP script and calling its open method with a reference to your system DSN, like this:

    <%

    Dim conn

    Set conn = Server.CreateObject("ADODB.Connection")

    conn.Open "DSN=TestDSN"

    If conn.errors.count = 0 Then

    Response.write "Connected OK"

    End If

    %>


    There are both advantages and disadvantages that result from using system DSN's to connect to a database. They are shown below:

    Advantages:
    • System DSN's are available to any authenticated windows user.
    • Details of the database connection are not stored in any physical file or ASP script, and are therefore more secure.
    • Because a system DSN is stored in the registry, it can be modified through the "Data Sources (ODBC)" tab just as easily as it can be created.
    Disadvantages:
    • Because system DSN's are stored in the registry, every time we use them to connect to our database from within ASP, the ASP engine has to do a registry lookup to get the DSN's connection and authentication credentials.
    • System DSN's are slower than using an OLEDB connection string directly. This is only slightly noticeable (approximately a 15% speed differential) when more than 10 users are concurrently connected.

    More ASP Articles
    More By Joe O'Donnell


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway