Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page doesn't work when I connect using DSN but does if not

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
This is the weirdest problem I have come across in a long time. The following code works if I use a dsn-less connection but if I use a dsn connection it doesn't. The page doesn't error it just doesn't display all the information. I have even put in a few lines at the bottom to make sure the recordset it is returning is the same and it is.

The results should look like this (using a DSN-less connection)

IT - BWBNet > Deeds
> HR
- Hardware knowhow > Memory
> Telephones
- Minutes
- Software knowhow > Adobe Reader
> Dictation Console
> Digital Dictation
> Modular Messaging
> Outlook
> VisualFiles
> Windows
> Winzip
> Workshare

But with a DSN they look like this (ie it is not displaying TBL("DocsCat")

IT - > Deeds
> HR
> Memory
> Telephones
> Adobe Reader
> Dictation Console
> Digital Dictation
> Modular Messaging
> Outlook
> VisualFiles
> Windows
> Winzip
> Workshare

My code is as follows:

<%

Set DB = Server.CreateObject("ADODB.Connection")
Set TBL = Server.CreateObject("ADODB.RecordSet")

DB.Mode = adModeReadWrite
'Comment or uncomment the DB.Open depending on which one you want to use
'DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("../../bwbnet/directory/userdb.mdb"))
DB.Open "bwbnet"

Department=Int(Request.QueryString("Department"))
TBL.Open "SELECT DocsDeptID, DocsDept.DocsDept, DocsCat.DocsCatID, DocsCat.DocsCat, DocsSubCat.DocsSubCatID, DocsSubCat FROM (DocsDept LEFT JOIN DocsCat ON DocsDept.DocsDeptID=DocsCat.DocsDept) LEFT JOIN DocsSubCat ON DocsCat.DocsCatID=DocsSubCat.DocsCat WHERE DocsDept.DocsDeptID=" & Department & " ORDER BY DocsDept.DocsDept ASC, Left(DocsCat.DocsCat, 250) ASC, DocsSubCat.DocsSubCat ASC", DB

%>
<body link="blue" alink="blue" vlink="blue">
<table cellspacing="0" cellpadding="5" width="100%">

<%
Do While Not TBL.EOF
%>

<tr>
<td>
<font face="verdana" size="2">
<%
If TBL("DocsDept")<>OldDocsDept Then
Response.Write("<a href='docslist.asp?Department=") & TBL("DocsDeptID") & "'>"
Response.Write(TBL("DocsDept"))
Response.Write("</a>")
End If
%>
</td>

<td>
<font face="verdana" size="2">
<%
If TBL("DocsCat")<>OldDocsCat Then
Response.Write("<b> - </b>")
Response.Write("<a href='docslist.asp?Department=") & TBL("DocsDeptID") & "&DocsCat=" & TBL("DocsCatID") & "'>"
Response.Write(TBL("DocsCat"))
Response.Write("</a>")
End If
%>
</td>

<td>
<font face="verdana" size="2">
<%
If TBL("DocsSubCat")<>"" Then Response.Write(" > ")
Response.Write("<a href='docslist.asp?Department=") & TBL("DocsDeptID") & "&DocsCat=" & TBL("DocsCatID") & "&DocsSubCat=" & TBL("DocsSubCatID") & "'>"
Response.Write(TBL("DocsSubCat"))
%>
</td>

<%

OldDocsDept=TBL("DocsDept")
OldDocsCat=TBL("DocsCat")
OldDocsSubCat=TBL("DocsSubCat")

TBL.MoveNext
Loop
TBL.Close
%>
</table>
<%
'Execute the same query and display recordset without formatting
TBL.Open "SELECT DocsDeptID, DocsDept.DocsDept, DocsCat.DocsCatID, DocsCat.DocsCat, DocsSubCat.DocsSubCatID, DocsSubCat FROM (DocsDept LEFT JOIN DocsCat ON DocsDept.DocsDeptID=DocsCat.DocsDept) LEFT JOIN DocsSubCat ON DocsCat.DocsCatID=DocsSubCat.DocsCat WHERE DocsDept.DocsDeptID=" & Department & " ORDER BY DocsDept.DocsDept ASC, Left(DocsCat.DocsCat, 250) ASC, DocsSubCat.DocsSubCat ASC", DB
Do While Not TBL.EOF
Response.Write(TBL("DocsDept")) & "|" & TBL("DocsCat") & "|" & TBL("DocsSubCat") & "<br>"
TBL.MoveNext
Loop
TBL.Close

Set TBL=Nothing
Set DB=Nothing

%>
 
Problem solved although I don't understand why.

Just after the line

If TBL("DocsCat")<>OldDocsCat Then

I put

Response.Write(OldDocsCat)

On every single line in the output it was showing up as a blank.

At the end I replaced

OldDocsDept=TBL("DocsDept")
OldDocsCat=TBL("DocsCat")
OldDocsSubCat=TBL("DocsSubCat")

with

OldDocsDeptID=TBL("DocsDeptID")
OldDocsCatID=TBL("DocsCatID")
OldDocsSubCatID=TBL("DocsSubCatID")

and then replaced

If TBL("DocsCat")<>OldDocsCat Then

with

If TBL("DocsCatID")<>OldDocsCatID Then

I think it might have something to do with my querystring in the <a href="... tag but I can't see what or why and why using a DSN/DSN-less connection should make any difference.

Problem solved though so shouldn't complain!

Ed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top