|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I am trying to test a beginners piece of ASP scripting: <% @language=VBScript %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Derek Robertson"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (Win95; U) [Netscape]"> <title>Active Server Page 02</title> </head> <body> <center><b><font size=+1>ASP Test Page</font></b> <p><b><i>This page is one which will be built up to interact with an MS Access database</i></b></center> Output: <br> <% intS= 60*60 %> There are <% response.write intS %> seconds in an hour. </body> </html> Why won't MSN Explorer or Netscape 6.2 interpret the ASP scripting? They handle the HTML OK, but just throw the ASP scripting back at me. I don't seem to have any beginners luck on this one! Regards Derek Last edited by Derek Robertson : September 15th, 2002 at 06:42 AM. |
|
#2
|
|||
|
|||
|
Hi Dereck,
Netscape and Explorer don't interpret ASP code. Your web server has to do that. Do you have your web server set up to handle the ASP code? Also, make sure that your page is in a folder where the web server has access to. |
|
#3
|
|||
|
|||
|
Sounds to me, that your just running it off your hard drive and not on a server configured for asp. In order to run any server side language, you must have a server configured to run that language on. For asp, you would probally want to look at IIS, as a server, to run your scripts
|
|
#4
|
|||
|
|||
|
What about the use of Personal Web Server? I have got that running in the bacground, but not responding properly. Maybe there is a complication because I am running Windows ME, and had to download Personal Web Server to a different directory?
Last edited by Derek Robertson : August 30th, 2002 at 02:43 PM. |
|
#5
|
|||
|
|||
|
Hi Derek,
Did you install Option Pack 4 on your personal webserver? I am running PWS on a Win ME system without problems, ie can read ASP files. But in order for you to make it work download option pack 4: http://www.microsoft.com/ntserver/n...tPk/default.asp and install. Ensure your asp page is in a directory where PWs has access to and run the page using http://localhost/yourpage.asp Since asp is server side, your need to treat your computer as a webserver (which PWS does) You will see in your tray if PWS is running or not
__________________
- Rogier Doekes |
|
#6
|
|||
|
|||
|
Hi Rogier,
Thank you for your helpful response. I did download Option Pack 4 from the MSN site you quoted. Installation of OP4 kept giving various error messages, so I surfed about, and used the advice given by Mike Burgess at Microsoft MVP http://www.users.qwest.net/~careyh/fixes.htm >>QUOTE: Problem: How can I add PWS to windows ME? Possible Solution: From Mike Burgess, Microsoft MVP (How To Install PWS in Windows Me: http://members.home.net/winhelp98/pws.htm) Q266456 - Personal Web Server Is Not Included with Windows Millennium Edition http://support.microsoft.com/suppor...s/Q266/4/56.asp Use the patch from this Microsoft Knowledgebase Article first: Error Message: An Unknown Error Occurred While Making MTS Specific Changes to the System Registry http://support.microsoft.com/suppor...s/Q246/0/81.ASP Install PWS IN custom MODE and ONLY install Transaction Server, SETUP will prompt you, that other components are needed. Get it down to basically just Transaction Server, core components and MDAC. Reboot and then run Setup again via Add/Remove and install the other components. (Personal Web Server, etc..) If you already have PWS installed, try removing everything via Add/Remove but Transaction Server then reboot. Run Setup again to add the rest. >>UNQUOTE After getting PWS installed successfully, the present situation is that I have a PWS icon in my system tray, and it shows "Personal Web Server is running" Your point about: Ensure your asp page is in a directory where PWs has access to and run the page using http://localhost/yourpage.asp seems to be my current problem. The file I am trying to test resides in my c:\inetpub\wwwroot\dmrweb and it has a filename with a ".html" file extension. How do I get PWS to test that file? Thanks again Regards Derek |
|
#7
|
|||
|
|||
|
try to save the file with a .asp extension and run it again using
http://localhost/drwweb/yourfile.asp Also ensure your properties are setup right: - dubble click on the PWS icon in your tray - click Advanced - Click Edit Properties - verify the directory (and the wwwroot directory) has read and scripts access Then it should work. success |
|
#8
|
|||
|
|||
|
Quote:
lol iis 5 or apache with the asp module would help you see your asp scripts as other's have mentioned this ![]()
__________________
Apache Expert |
|
#9
|
|||
|
|||
|
Hi asp_man,
See above: ASP runs server side. this means you need to configure your computer as a server. See abow how to download option pack 4 for PWS. You need this to run asp files. Which browser you use does not matter, again, since asp runs server side. see here a tutorial on beginning with ASP: http://www.devguru.com/features/tutorials/ASP/ASP.html |
|
#10
|
|||
|
|||
|
Thanks to all contributors,
I have now got some simple ASP working, and I want to move on to using ASP to go to an Access 2000 database, which is parked in my c:\inetpub\databases At this stage I need to be sure that I understand fully the personalised pieces of the tutorial line: DataConn.Open "DSN=dsnname;SRVR=server IP address;UID=username;PWD=password" For dsnname I put myfile.mdb For server IP address I put c:\inetpub\databases In ODBC Data Sources > System DSN > Name I added myfile.mdb and left Description blank also under Advanced I left Default Authorisation blank On trying to test myfile.asp I get the message: Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified What do I need to do now please? Regards Derek |
|
#11
|
|||
|
|||
|
Hi Derek
The tutorial you read speaks of a DSN, which is a ODBC connection. ODBC stands for Open DataBase Connection, which is microsoft way of handling connections to databases. DSN less connection also exist, but that's another matter. What you need to do: 1. Go Start/ settings/Control Panel/ODBC Data Source 2. Go to the tab System DSN 3. Click Add.. 4. Select the Access Driver and click Finish 5. Under Data Source Name enter a name 6. Desciption is for reference 7. Click Select and select the database 8. After OK, your DSN is ready Now in your ASP connection string you reference the name you gave under point 5: cnn.Open "dsn=see_5;Uid=;Pwd=" success -Rogier |
|
#12
|
|||
|
|||
|
Thanks Rogier,
Having done as you suggested, I now get no error messages. Now we come to pulling information from the database. Line 1 of the 4 lines discussed in the tutorial: StrSQL = "SELECT * from TABLE" I substituted mytablename in place of TABLE Line 4 of 4 in tutorial: Set TABLE = DataConn.Execute(strSQL) I substituted mytablename in place of TABLE Is the case of the "s" in str important? Line 1 in the tutorial uses "StrSQL" and Line 4 uses "strSQL" I got no information from the TABLE. Regards Derek |
|
#13
|
|||
|
|||
|
option explicit
VBscript is a weak typed language, meaning that all your variables can be of any type.
However, it is a good programming habit to start each asp file with the following snippet: <% Option Explicit%> This means that you explicitely have to define your variables: you do this with the Dim statement So this is correct programming: Dim oCnn, strSQL Set oCnn = Ser........ strSQL = "Select......" If you type now oCnn.Execute (sql) you will get an error message saying that variable sql is not defined, which is good, since you would like to use strSQL.. see http://www.devguru.com/Technologies...ickref/dim.html -Rogier |
|
#14
|
|||
|
|||
|
Hi Rogier,
I have tried the Option Explicit advice. I have now first success in getting information from my database, in that the first record is output OK. But I cannot get the Do....Loop to retrieve subsequent records to EOF. The contents of my test file are currently: <% @language=VBScript %> <!-- Option Explicit --> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Derek Robertson"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (Win95; U) [Netscape]"> <title>ASP Test SQL</title></head> <body> <% Dim DataConn, StrSQL %> <% Set DataConn = Server.CreateObject("ADODB.Connection") %> <% StrSQL = "SELECT * from icon_database" %> <% DataConn.Open "DSN=icon-ps_trial;UID=;PWD=" %> <% icon_database = DataConn.Execute(StrSQL) %> <% Do Until icon_database.EOF %> <br><br><% response.write icon_database ("id") %> <br><br><% response.write icon_database ("pkey") %> <br><br><% response.write icon_database ("title") %> <br><br><% response.write icon_database ("refno") %> <br><br><% response.write icon_database ("description") %> <br><br><% response.write icon_database ("start") %> <br><br><% response.write icon_database ("location") %> <br><br><% response.write icon_database ("category") %> <br><br><% response.write icon_database ("salary") %> <% icon_database.MoveNext Loop %> </body> </html> I get two error messages: For start of Do Loop: Microsoft VBScript runtime error '800a01b6' Object doesn't support this property or method: 'EOF' For increments to next record: Microsoft VBScript runtime error '800a01b6' Object doesn't support this property or method: 'MoveNext' How do I get the Do....Loop to work? Regards Derek Last edited by Derek Robertson : September 14th, 2002 at 01:08 AM. |
|
#15
|
|||
|
|||
|
Re: Communicating with an Access Database
Hello Derk...
You have made your code very complex... You must use i.e. <% statements statements statements %> you must use while loop... i think it would work fine.... i.e. while not icon_database.eof statements statements statemetns wend i dont know what the problem... database access is so simple... <html><head><% strConnect = ----your connection string----%> </head><body> <% dim objRS set objRS = server.createobject("ADODB.REcordset") objRS.open "TableName", strConnect while not objrs.eof response.write objRS("field1") response.write objRS("Field2") -------- -------- objRS.MoveNext wend objRS.close set objrS=nothing %> |
|
#16
|
|||
|
|||
|
Thanks Nauman,
I tried the "while" coding, and I get two error messages: Object doesn't support this property or method: 'eof' Object doesn't support this property or method: 'MoveNext' Is there something missing from my Microsoft Personal Web Server? Regards Derek |
|
#17
|
|||
|
|||
|
have you created the recordset object?
problem may also be case sensitivity or ado constants, i noticed you dont have any declared for the cursortype or lock type. this may cause the error. if you have declared objRS or RS as a variable but not set it as a recordset object then it wont support End of file or move next - they are recordset only functions. make sure you have: dim objRS Set objRS = CreateObject("ADODB.Recordset") objRS.Open "select * from here", adOpenStatic, adLockReadOnly if not objRS.EOF then while objRS.EOF = false with response .write trim(objRS("something)) .write "<br>" end with wend else response.write "no records" end if The code above also needs a connection object declaring and provider information - presume you have this either as a DSN or a hardcoded server.mappath url make sure you close connection objects and recordset objects at the end of each page - not essential but good practice. i.e.: objRS.close set objRS = Nothing Last edited by » Matt M « : September 16th, 2002 at 12:25 PM. |
|
#18
|
|||
|
|||
|
Thanks Matt M,
I will recheck my scripting and report back. Regards Derek |
|
#19
|
|||
|
|||
|
Thanks to all Contributors,
I am now able to communicate with my trial database. Any comments about the following scripting will be welcomed, particularly anything relating to "good scripting practice": <% @language=VBScript %> <% Dim DataConn, StrSQL, rs Set DataConn = Server.CreateObject("ADODB.Connection") StrSQL = "SELECT * from icon_database" DataConn.Open "DSN=icon-ps_trial;UID=;PWD=" set rs = Server.CreateObject("ADODB.recordset") icon_database = DataConn.Execute(StrSQL) rs.Open Strsql, DataConn %> <body text="#000000" bgcolor="#ff6600" link="#0000ee" vlink="#00ff00" <%while rs.EOF=false%> <table border="5" width="100%" bgcolor="#ff9900"> <td align="center"> <tbody> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <br> <%wend rs.close DataConn.close %> Next task I will tackle is to use a Data Form Wizard to create a form which will read and / or amend the database. Any comments about VB6 in 24 Hours, Hour 15, p263-264 ? But, is it true that the Data Form Wizard is only available in the full version of VB 6.0, and that it is not included in VB 6.0 trial versions? Regards Derek Last edited by Derek Robertson : September 20th, 2002 at 02:26 AM. |
|
#20
|
|||
|
|||
|
Hi Again Matt M,
Please see and comment on my posting about successful scripting. Regards Derek Last edited by Derek Robertson : September 20th, 2002 at 02:22 AM. |
|
#21
|
|||
|
|||
|
Hi Again Rogier,
Please see and comment on my posting about successful scripting. Regards Derek Last edited by Derek Robertson : September 20th, 2002 at 02:23 AM. |
|
#22
|
|||
|
|||
|
Hi Again Nauman,
Please see and comment on my posting about successful scripting. Regards Derek |
|
#23
|
|||
|
|||
|
Hi Again asp_man,
Please see and comment on my posting about successful scripting. Regards Derek |
|
#24
|
|||
|
|||
|
Hi Again markerdave,
Please see and comment on my posting about successful scripting. Regards Derek |
|
#25
|
|||
|
|||
|
Hi Again Ben Rowe,
Please see and comment on my posting about successful scripting. Regards Derek |
|
#26
|
|||
|
|||
|
Re: see abow
Quote:
uhmm what do you think IIS and Apache are? they are servers unless i'm missing something here... no need to help me man i'm a pro with this stuff....![]() |
|
#27
|
|||
|
|||
|
Reading the thread back, sorry that I gave you a piece of advice that was clearly not intended for you.
Me bad. -Rogier |
|
#28
|
|||
|
|||
|
Re: sorry asp_man
Quote:
it's cool no biggie .![]() |
|
#29
|
|||
|
|||
|
Hi Derek,
I tend to keep all of my connection information together. I put that info in an include file, so that I can reuse it on every asp page I create and not have to retype it. (Alternatively, you can include you connection info in a global.asa file.) That way, if you ever need to change your connection string, you only have to change it in one place. So I would create a file called connect.asp (don't use inc extension for connection info as that has been found to be insecure). For sake of organization, I put all my include files in an "include" folder. It would simply consist of the following: Code:
<%
Dim DataConn
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.ConnectionString = "DSN=icon-ps_trial;UID=;PWD="
DataConn.Open
%>
Then at the top of your asp page put: <!--#include file="include/connect.asp"--> <% dim strSQL dim rs strSQL = "SELECT * from icon_database" set rs = DataConn.Execute(StrSQL) %> <body text="#000000" bgcolor="#ff6600" link="#0000ee" vlink="#00ff00" <%while rs.EOF=false%> <table border="5" width="100%" bgcolor="#ff9900"> <td align="center"> <tbody> <tr> <%for each x in rs.Fields%> <td><%Response.Write(x.value)%></td> <%next rs.MoveNext%> </tr> <br> <%wend rs.close DataConn.close %> I always set my variables to nothing, in addition to closing them so after rs.close, I would write: Code:
set rs = nothing same with DataConn. Code:
set DataConn = nothing It also appears that you are combining two methods - SQL and ADO. I indicated above how you would do it with SQL command. For ADO, you would use the following: Code:
strSQL = "SELECT * from icon_database"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open strSQL, DataConn, 1, 3
Hope this helps. Last edited by aspnewbie : October 13th, 2002 at 10:32 AM. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Testing of Active Server Pages scripting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|