dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Web
Expertise: Beginner
Aug 26, 1999

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Quickly Establish a Database Connection from ASP Using File DSN

To quickly establish a database connection from ASP, try using a file DSN. The DSN string should not contain spaces, either, before or after the equal sign (=). In this case, the recordset object's Open method refers to the file based DSN, containing location and configuration information about the database. Remember to create the file DSN before using it in the code. Another option is to refer directly to an explicit provider, data source, user ID, and password, rather than to a DSN.

An example to access a database from ASP using file DSN is shown below (remember to put the code in <% and %>):

 
 ' Create connection object
 Set cn = Server.CreateObject("ADODB.Connection")
 cn.Open "FILEDSN=TestWeb.dsn"
  
 strSQL = "select FirstName,LastName FROM person"
  
  'Instantiate a Recordset object
  Set rsResults = Server.CreateObject("ADODB.Recordset")
  rsResults.Open  strSQL, cn
  
  Set objFirstName = rsResults("FirstName") 
  Set objLastName = rsResults("LastName")  
  
  Do Until rsResults.EOF   
   Response.Write objFirstName & " " & objLastName & "<BR>"
   rsResults.MoveNext
  Loop

   ' Clean up is a good practice
  cn.Close
  Set rsResults  = nothing
  Set cn = nothing
Jai Bardhan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date