neronikita
Technical User
Hello. I have used ASP before but I never set up my own database connection in it. Would someone please look at this and tell me why the page will not display... it works for the first section of asp, but when I add in the second part with the connection to the database. I am new to sql server 2008, but my DSN connection works when tested. I've also tried non-dsn connection and couldn't get that to work. Can anyone tell me what I'm doing wrong? I have replaced the pw and ID with generics, but nothing else has changed in this code.
Thanks
Di
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html>
<head>
<title>My First ASP Page</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim strMessage
'Place the value Hello World into the variable strMessage
strMessage = "Hello World"
'Write the contents of the variable strMessage to the web page
Response.Write (strMessage)
'Write line break into the web page
Response.Write ("<br>")
'Write the server time on the web page using the VBScript Time() function
Response.Write ("The time on the server is: " & Time())
'Close the server script
%>
<%
'declare the variables
Dim Connection
Dim Recordset
Dim SQL
'declare the SQL statement that will query the database
SQL = "SELECT * FROM emptype"
'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'open the connection to the database
Connection.Open "DSN=ESI;UID=id;PWD=password;Database=ESI"
'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection
'first of all determine whether there are any records
If Recordset.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Do While NOT Recordset.Eof
Response.write Recordset("ID")
Response.write Recordset("Description")
Response.write "<br>"
Recordset.MoveNext
Loop
End If
'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
</body>
</html>
Thanks
Di
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html>
<head>
<title>My First ASP Page</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim strMessage
'Place the value Hello World into the variable strMessage
strMessage = "Hello World"
'Write the contents of the variable strMessage to the web page
Response.Write (strMessage)
'Write line break into the web page
Response.Write ("<br>")
'Write the server time on the web page using the VBScript Time() function
Response.Write ("The time on the server is: " & Time())
'Close the server script
%>
<%
'declare the variables
Dim Connection
Dim Recordset
Dim SQL
'declare the SQL statement that will query the database
SQL = "SELECT * FROM emptype"
'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'open the connection to the database
Connection.Open "DSN=ESI;UID=id;PWD=password;Database=ESI"
'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection
'first of all determine whether there are any records
If Recordset.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Do While NOT Recordset.Eof
Response.write Recordset("ID")
Response.write Recordset("Description")
Response.write "<br>"
Recordset.MoveNext
Loop
End If
'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
</body>
</html>