Web Development

  Homes arrow Web Development arrow Connecting to a database with a DSN
 Webmaster Tools
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
Password Strength
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Forums Sitemap 
Weekly Newsletter
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
  >>> SIGN UP!  
  Lost Password? 

Connecting to a database with a DSN
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0

    Table of Contents:

    Rate this Article: Poor Best 
      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




    by: Codefixer.com

    Connecting to a database with a DSN

    If you do not know how to set up a system dsn i suggest you read this article first of all before attempting this tutorial.

    For our example lets assume that our DSN points to an Access database called News.mdb and that we will be selecting records from the table tblNews.

    <% @ Language="VBScript" %>
    <% Option Explicit %>
    'declare your variables
    Dim connection,dsn,recordset, sql

    'declare the SQL statement that will query the database

    sql="SELECT * FROM tbNews"

    'initialise the dsn variable
    dsn="dsn=mydsn"    'mydsn will be the name you have chosen for your dsn

    'create an instance of the ADO connection and recordset objects
    Set connection = Server.CreateObject("ADODB.Connection")
    Set recordset = Server.CreateObject("ADODB.Recordset")

    'Open the connection to the database
    connection.Open dsn

    'Open the recordset object, execute the SQL
    recordset.Open sql,connection

    'now lets see if there are any records returned
    If Not recordset.Eof Then
    response.write "There are records."
    response.write "There are no records
    End If

    'close the connection and recordset objects and free up resources

    Set recordset = Nothing
    Set connection = Nothing

    Remember that mydsn above is the dsn that you named and created.
    Note you can change the table name from tblNews to the name of your table and point the DSN to whatever database you like.
    One other thing to remember is that you can set up a dsn on your own machine though if you are using a hosting company you may have to ask the webmaster.

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed



    - On Page SEO for New Domains
    - Improve Your Site`s Speed
    - Safari Books Online Review
    - Creating an Estore From the Ground Up
    - Most Common SEO Mistakes Developers Make
    - Making the Most of Your Titles and Meta Desc...
    - Five Ways Using Flash Can Damage Your Site
    - A Web Designer`s Guide to Colors
    - Use Webstarts to Create a Free Site
    - More Than Just Looks. How Your Web Design C...
    - How to Design Content Pages
    - Mint Review
    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?

    Developer Shed Affiliates


    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap