Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2007, 12:03 AM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default DataRead already open

Hi All,

I have decided to make the move over from classic ASP to dot net. I have written my first scraping script that reads from a database website addresses then loops through a list of keywords also on the database.

All works fine on my DEV maching but when i post it to the webserver i get. The error:

Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.

I cant understand why this would happen? Can anyone provide some advise.

Thanks in advance

Tim


Code:
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>

<script language="VB" runat="server">

Sub Page_Load(Sender as Object, E as EventArgs)
Dim Website, keywords As String

'// Connection string
Dim connString as String
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _
             "C:\Inetpub\www\WebsiteScrape\Scraping.mdb"

'// Database connection
Dim objConn As OledbConnection
objConn = New OledbConnection(connString)
objConn.Open() ' open connection

'// Get Websites
Dim strSQL, strKey As String
strSQL = "SELECT Website FROM Websites"



'// Create Website SQL Command
Dim objWebsites as OleDbCommand
    objWebsites = New OledbCommand(strSQL, objConn)



'// Create Website Reader
Dim objReader As OledbDataReader
    objReader = objWebsites.ExecuteReader(CommandBehavior.CloseConnection)



'// Loop through the Website addresses
Response.Write("<h2>Checking domain list</h2>")
While objReader.Read()

'// Get Keywords
strKey = "SELECT Keywords FROM Keywords"

'// Create Keywords SQL Command
Dim objKeywords as OleDbCommand
    objKeywords = New OledbCommand(strKey, objConn)

'// Create Keyword Reader
Dim objReader2 As OledbDataReader
    objReader2 = objKeywords.ExecuteReader(CommandBehavior.CloseConnection)

    Response.Write("<b>Checking domain: </b><a href='" & objReader("Website") & "' target='_blank'>" & objReader("Website") & "</a><BR>")

    '// Scrape the select websites
    Website = objReader("Website")
    Response.Write("<i>Scanning keywords:</i><BR>")
    While objReader2.Read()
    Response.Write("&nbsp;&nbsp;  &raquo; " & objReader2("Keywords") & " ")
    keywords = objReader2("Keywords")
        '// Loop keywords

            Dim oRequest As WebRequest = WebRequest.Create(Website)
            Dim oResponse As WebResponse = oRequest.GetResponse()

            Dim oStream As Stream = oResponse.GetResponseStream()

            Dim oStreamReader As New StreamReader(oStream, Encoding.UTF8)
            Dim URL as string
            Dim KeywordFinder As String

            'Response.Write(oStreamReader.ReadToEnd())
            URL=oStreamReader.ReadToEnd()
            KeywordFinder = InStr(URL, keywords)
            oResponse.Close()
            oStreamReader.Close()
            If KeywordFinder > 0 Then
            Response.Write("YES (<i>First instance of '"& keywords &"' line: " & KeywordFinder & ")<BR>")
            Else
            Response.Write ("NO<BR>")
            End If


    End While

'// Clean variables
Website = ""
keywords = ""

End While

'// Close connections
objReader.Close()


End Sub


</script>
TDA
__________________
TDA





Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Form, run query, open form Grafixx01 Access 7 April 26th, 2007 11:32 AM
Open document, Open second doc and copy to first justabeginner Word VBA 1 March 7th, 2007 02:47 AM
asp can't open db when db open by other program datuk Classic ASP Professional 3 June 13th, 2006 06:10 PM
Open the "Open File" dialogue box piratelordx Access VBA 4 March 14th, 2006 10:08 PM
Attempted to open a database that is already open person747 Access 10 September 3rd, 2004 04:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.