[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

Pulling information out of an Microsoft ACESSS Database and displaying the information on a webpage.

Im having trouble getting this to work, and honestly I dont know where to really start on this, I want to pull product information out of a database and display it on a webpage using asp, but I get error messages and to be honest I dont know where to start or if im even doing it right. TO get a better IDEA of my problem goto  Http://www.rhjgold.com, click on the wax catalog button and then click on the diamond fashion button,  I want to pull all products in that database out, and display them.  here is the code and the error messages im getting.

Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/dfashionwax.asp, line 8

Invalid class string




Here is the code:

<%
 ' open database connection
set db1 = Server.CreateObject("ADODB.Connection")
'    db1.Open "DSN=DB2094a;UID=*****;PWD=*****"
' open recordset

' open Recordset
Set RS = Server.CreateObject( "ADODB.Recordest" )
RS.ActiveConnection = db1
RS.Open "SELECT * FROM diamondfashion"

' loop through Recordset
WHILE NOT RS.EOF

Response.Write RS( "product_name" )
RS.MoveNext
WEND

%>
0
Aencinger1
Asked:
Aencinger1
  • 6
  • 2
  • 2
1 Solution
 
Ryan ChongCommented:
>>Set RS = Server.CreateObject( "ADODB.Recordest" )

typo?? try this instead:

Set RS = Server.CreateObject( "ADODB.Recordset" )
0
 
aprestoCommented:
I always use the same db connection for everything,:

<%
'Declare your variables
Dim strDB, conn, strcon, rs  

'Set database path variable
strDB = "db/mydatabase.mdb"

'Set a variable called Conn as your connection variable
Set Conn = Server.CreateObject("ADODB.Connection")

'Set up your Database drivers
strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.MapPath(strDB)

'Open the database connection
Conn.Open strCon

'Now to get your info into a recordset and display it
'Tell the page that the variable called rs will be a recordset
Set rs = server.createobject("ADODB.recordset")

'Store info from the database in the recordset - Always remember to put the connection variable at the end of these (conn)
rs.open "SELECT * FROM diamondfashion", conn
 
IF not rs.eof Then                                                        'IF the SELECT picked up info THEN
     While not rs.eof                                                      'WHILE the recordset is NOT EMPTY
        response.write rs("Product_name") & "<BR>"        'TYPE THE FIRST PRODUCT_NAME and line break
      rs.movenext                                                          'Move to the next record
    Wend                                                                     'End the WHILE loop when there are no more records
Else                                                                           'IF the SELECT did NOT PICK UP INFO THEN
    Response.write "There are no procucts to display"     'Write this to the screen
End If                                                                        'END IF

...

%>


Thats how i would do it, ive tried to make it all pretty vlear, ryancys is right but this is an alternate method, if u paste it it should work
0
 
Aencinger1Author Commented:
ok, im really close to makeing this work now... after entering all the information in the selected spots, I now only get the following error.

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.


I think I must have something wrong in here, this is the new code:

<%
'Declare your variables
Dim strDB, conn, strcon, rs  

'Set database path variable
strDB = "fpdb/njbatabase.mdb"

'Set a variable called Conn as your connection variable
Set Conn = Server.CreateObject( "ADODB.Connection" )

'Set up your Database drivers
strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=*****;pwd=*****; DSN=DB2094A; DBQ=" & Server.MapPath(strDB)

'Open the database connection
Conn.Open strCon

'Now to get your info into a recordset and display it
'Tell the page that the variable called rs will be a recordset
Set rs = server.createobject("ADODB.recordset")

'Store info from the database in the recordset - Always remember to put the connection variable at the end of these (conn)
rs.open "SELECT * FROM diamondfashion", conn
   
IF not rs.eof Then                                                        'IF the SELECT picked up info THEN
     While not rs.eof                                                      'WHILE the recordset is NOT EMPTY
        response.write rs("product_name") & "<BR>"                       'TYPE THE FIRST PRODUCT_NAME and line break
      rs.movenext                                                          'Move to the next record
    Wend                                                                     'End the WHILE loop when there are no more records
Else                                                                           'IF the SELECT did NOT PICK UP INFO THEN
    Response.write "There are no procucts to display"     'Write this to the screen
End If                                                                        'END IF


%>

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
aprestoCommented:
Are you still having tha problem.  what line does this error point to :

[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.

Thanks for the points and grade :o)
0
 
aprestoCommented:
I think its your database driver, you may need to change to OLEDB:

http://www.frontpagewebmaster.com/m-10783/tm.htm

http://www.tek-tips.com/viewthread.cfm?qid=943424&page=6

These are some references i found that may help, if they do not let me know.  But this is assuming the error points to this line:

Conn.Open strCon
0
 
Aencinger1Author Commented:
Ok, I found that the database I was trying to connect to did not have a username or password set, I got that fixed and now it appears that it is connecting to the database because it now gives me this error message:

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name or ordinal

I have checked everything six times, all the names are spelled correctly and its pointing to the right database.  I have checked the fields twice and checked the spelling twice.  Now im at a lost it says error on line 26 which appears to be:

 response.write rs("product_name") & "<BR>"                       'TYPE THE FIRST PRODUCT_NAME and line break

Any other help you could give me would be greatly appriciated.

Thank You
0
 
aprestoCommented:
Huum... Well normally this error:

Item cannot be found in the collection corresponding to the requested name or ordinal

Means that either the recordset is empty or the name of the field is wrong...

So you are sure that the field in the database is called product_name and not product name - no spaces

if this doesnt work, try storing rs("product_name") in a variable and calling that:

Dim Prod_name
Prod_name = rs("Product_name")

...


response.write Prod_Name & "<BR>"

Just to see if the error changes line
0
 
Ryan ChongCommented:
>>Item cannot be found in the collection corresponding to the requested name or ordinal
Make sure the "product_name" is selected from your statement query ?

you can try to debug it by putting a loop like:

for i = 0 to rs.fields.count - 1
   response.write rs.fields(i).name & "<br>"
next

but you can directly check that from your sql statement as well.
0
 
aprestoCommented:
if that doesnt work whats does your diamondfashion table look like, if you could respond with the names of the fields that would be great.  Just to be sure.

Bu i think tyancs suggestion will work
0
 
aprestoCommented:
*ryancys
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now