Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (43)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)

Main Category  Other
  Website Maintenance (3)
Log In
UserName Or Email:

Password:

Auto-Login:

Hosted by Securewebs.com
 
Home : .NET : ADO : How to display records from top 4 database systems using plain ASP?
 
Read full length articles at Stardeveloper using Twitter Follow on Twitter Facebook Facebook fan page Email Get Articles via Email RSS Get Articles via RSS Feed

How to display records from top 4 database systems using plain ASP?

by Ken Lin.

Sometimes, we would have chance to convert our existing database or create a new database. Some decisions IT professionals need to make are scary, and choosing database software is one of them. This overview aims to describe how to set database connections with some common database software. Hopefully, you would find it useful.

i. MS SQL Server

With DSN

<%
	Set conn = Server.CreateObject("ADODB.Connection")
	conn.Open "DSN=DSNname;UID=username;PWD=password;DATABASE=databasename"
%>

Without DSN

<%
	DSN1 = "DRIVER={SQL Server};SERVER=servername;UID=username;" & _
		"PWD=password;"
	DSN1 = DSN1 & "DATABASE=databasename"

	Set conn = Server.CreateObject("ADODB.Connection")
		conn.Open DSN1
%>

ii. Oracle

ODBC with DSN

<%
	Set conn = server.createobject("adodb.connection")
		conn.CursorLocation = adUseClient   
		conn.Open "DSN=DSNname;UID=username;PWD=password"
%>

iii. MS Access

i.) With DSN and no username/password

<%
	Set conn = Server.CreateObject("ADODB.Connection")
		conn.Open "DSNname"
%>

ii.) With DSN and User ID/Password

<%
	Set conn = Server.CreateObject("ADODB.Connection")
		conn.Open "DSNname","username","password"
%>

iii.) Without DSN
Using physical path as a reference:

<%
	DSN1="DRIVER={Microsoft Access Driver (*.mdb)}; "
	DSN1=dsntemp & "DBQ=c:\mywork\accounting.mdb" 

	Set conn = Server.CreateObject("ADODB.Connection")
		conn.Open DSN1
%>

Using Server.MapPath, which is the path from the webserver root (by default, c:\inetpub\wwwroot).

<%
	DSN1="DRIVER={Microsoft Access Driver (*.mdb)}; "
	DSN1=dsn1 & "DBQ=" & Server.MapPath("/mywork/accounting.mdb")

	Set conn = Server.CreateObject("ADODB.Connection")
		conn.Open DSN1
%>

iv. MySQL Databases :
You need to supply a database name because in MySQL you can have mulitple databases on the same SQL server.

<% 
	strConnection = "driver={MySQL};server=localhost;uid=username;"
	strConnection = strConnection & "pwd=password;database=databasename" 

	Set conn = Server.CreateObject("ADODB.Connection") 
		conn.Open strConnection 
%>

Now, the database connections would be established. Next, we would need to retrieve data from the database.

Below is an example that assumes we've got a list of email addresses.

Table Name: emailadds 

name              emailadd 

------------------------------------------------------ 

Ken 		  ken@prect.com
...		  ...........

We write a query to list and output all the names and email address in a table.

<% 
	strQuery = "SELECT * FROM emailadds"

	Set rsEmailData = adoDataConn.Execute(strQuery)

	If Not rsEmailData.BOF Then 
%>

<TABLE> 
</span><TR>
<TD<b>Name</b></TD>
<TD><b>Email Address</b></TD>
</span></TR> 

<% 
	Do While Not rsEmailData.EOF 
%> 

</span><TR>
<TD><%=rsEmailData("name").Value %></TD>
<TD><%=rsEmailData("emailadd").Value %></TD>
</span></TR> 

<% 
	rsEmailData.MoveNext 
	Loop 
%> 

</TABLE> 
<%
	Else
		Response.Write("Sorry, no email addresses found.") 
	End If
%>

After using databases, you should close the database and the record set so that occupied memory can be released.

<% 
	rsEmailData.Close
	adoDataConn.Close

	Set adoDataConn = Nothing 
	Set rsEmailData = Nothing 
%>

 ( No Further Pages )

Related Articles
  1. Uploading Files into an Access Database using plain ASP
  2. Displaying Images from an Access Database using plain ASP
  3. Fastest way of Database Access : Caching Records in Memory
  4. Adding records to the database with ASP
  5. DSN vs DSN less Database Connections
  6. Searching and sorting records in a recordset from the database
  7. Speedup Database Access using GetRows
  8. Inserting Form content into Database with ASP
  9. Using ASP pages to page through Recordsets
  10. Generating Random Records from the Database

Comments/Questions ( Threads: 1, Comments: 1 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. MS Excel

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.