Simple query returns 0 records in asp, but all records in vbscript

M

masg0013

I have a few vbscripts that I want to convert to asp pages so I can
use html to format the data better.

1). Do asp pages have to be run from an IIS server or can I just
create them locally and then open them in IE?

2) The following connection strings, accounts and queries work fine in
vbs files but I am getting 0 results when I run them as asp. I don't
know how to debug them to figure out the issue

here is the code

<%@ language="VBSCRIPT" %>
<html>
<head>
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 4.0">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>CFG site</title>
</head>
<body>

<%
Dim objConnection, dsn
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=SQLOLEDB;Data Source=servername;" & _
"Trusted_Connection=Yes;Initial Catalog=edfcm4;" & _
"User ID=user;Password=password;"
Set rs=objConnection.Execute ("SELECT machine_name FROM
ecm_dat_machines")
%>
<table border="1">
<%
Do While Not rs.EOF
%>
<tr>
<td><%= rs.Fields("ecm_dat_machines.machine_name")%></td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>
<%
Set objConnection = Nothing
%>
</body>
</html>
 
M

Mike Brind

I have a few vbscripts that I want to convert to asp pages so I can
use html to format the data better.

1). Do asp pages have to be run from an IIS server or can I just
create them locally and then open them in IE?

2) The following connection strings, accounts and queries work fine in
vbs files but I am getting 0 results when I run them as asp. I don't
know how to debug them to figure out the issue

here is the code

<%@ language="VBSCRIPT" %>
<html>
<head>
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 4.0">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>CFG site</title>
</head>
<body>

<%
Dim objConnection, dsn
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=SQLOLEDB;Data Source=servername;" & _
"Trusted_Connection=Yes;Initial Catalog=edfcm4;" & _
"User ID=user;Password=password;"
Set rs=objConnection.Execute ("SELECT machine_name FROM
ecm_dat_machines")
%>
<table border="1">
<%
Do While Not rs.EOF
%>
<tr>
<td><%= rs.Fields("ecm_dat_machines.machine_name")%></td>

1. ASP pages must be run against an asp-enabled web server. If you have XP
Pro, you can add IIS 5.1 by going to Control Panel -> Add Or Remove
Programs - > Add/Remove Windows Components then ticking Internet Information
Services. If you open them in the browser directly, they are not processed
by the ASP engine, so the script will appear as text.

2. Wrong syntax. Try <%=rs("machine_name")%>. Don't include the table
name.

Couple of other things: you declared a variable called dsn, but never used
it. While you set the connection to nothing, you left the recordset alone.
You should close that and set it to nothing once you're done with it, too
(before finishing with the connection).
 
E

Evertjan.

wrote on 02 nov 2006 in microsoft.public.inetserver.asp.general:
1). Do asp pages have to be run from an IIS server or can I just
create them locally and then open them in IE?

ASP code only runs through the ASP interpretor, that converts output to a
html stream that is sent to the requesting browser.

Running an asp file in a browser will get you nowhere.
2) The following connection strings, accounts and queries work fine in
vbs files but I am getting 0 results when I run them as asp.

I strongly advice you against database handling trough ASP untill you have
mastered the concepts of ASP and it's script languages.
[Read the archive of this NG and the de facto faq http://www.aspfaq.com,
and a simple asp tutorial perhaps]
I don't
know how to debug them to figure out the issue

Basic debuging goes by inspecting error messages and putting

response.write yourVariableToBeRead
response.end

[vbscript version] breakpoints in strategic places.
 
A

Anthony Jones

I have a few vbscripts that I want to convert to asp pages so I can
use html to format the data better.

Doesn't sound like ASP is what you need.

Continue to use VBS files. Research how to Automate IE to which you can
write the HTML output of the VBS. Here's a start for 10:-

Dim oIE : Set oIE = WScript.CreateObject("InternetExplorer.Application")

oIE.menubar = false
oIE.toolbar = false
oIE.statusBar = false
oIE.navigate "about:blank"
oIE.visible = true

Do While oIE.Busy
WScript.sleep 100
Loop

Dim oDoc : Set oDoc = oIE.document

oDoc.open
oDoc.write "<html><body>Hello World</body></html>"
oDoc.close


For more advanced application you could consider creating a HTA.


Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top