Results 1 to 5 of 5

Thread: 'ADODB.Connection' cannot be created

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    26

    'ADODB.Connection' cannot be created

    For the life of me, I cannot get this code run.

    Here's my code

    Code:
    <%@ LANGUAGE="VBScript" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <%
    'http://support.alentus.com/databases_conn_odbc.asp?Node=R&sNode=6&Exp=Y
    dim cs ' Connect string
    dim db ' Database object
    dim rs ' Recordset object
    
        cs = "DSN=prodlgo; UID=Sharon; PWD=sms999;"
    
        db = Server.CreateObject("ADODB.Connection")
        db.Open (cs)
    
        'rs = db.Execute(" & chr(34) & "SELECT * FROM employee" & chr(34) & ")" & vbcrlf & vbcrlf
        rs = db.Execute("SELECT * FROM employee")
        if (rs.EOF = True) or (rs.BOF = True) then
            Response.Write ("No records were found!")
        else
            rs.MoveFirst
            while (rs.EOF = False)
            'access table colums here in this manner
                Response.Write (rs("ee_emp_name"))
                Response.Write ("<BR>")
                rs.MoveNext
            End While
    
            Response.Write ("No more data!")
        end if
    
        db.Close
    
    %>
    
    <html>
      <head>
        <title>WebForm5</title>
      </head>
      <body MS_POSITIONING="GridLayout">
    
        <form id="Form1" method="post" runat="server">
    
        </form>
    
      </body>
    </html>
    I keep getting this error:
    Code:
    The component 'ADODB.Connection' cannot be created. Apartment threaded components can only be created on pages with an <%@ Page aspcompat=true %> page directive. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Web.HttpException: The component 'ADODB.Connection' cannot be created. Apartment threaded components can only be created on pages with an <%@ Page aspcompat=true %> page directive.
    
    Source Error: 
    
    Line 11:     cs = "DSN=prodlgo; UID=Sharon; PWD=sms999;"
    Line 12: 
    Line 13:     db = Server.CreateObject("ADODB.Connection")
    Line 14:     db.Open (cs)
    Line 15:
    I'd like to use this code, however I keep getting the above error. What is <%@ Page aspcompat=true %>? Can I use this code for my version of VB.NET STD 2003?

    Any help would be appreciated
    Thanks

  2. #2
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Re: 'ADODB.Connection' cannot be created

    Recordsets no longer exists. Now with ADO.NET you have to use Datasets.

    Since you want to use something which is in ASP and not in ASP.NET, the frmaekwork needs to be TOLD that you are using some ASP code and so the Page directive, <%@ Page aspcompat=true %> - Implying that the page needs to be compatible with ASP and ASP.NEt as well.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    26

    Re: 'ADODB.Connection' cannot be created

    Thanks John (veryjonny)

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: 'ADODB.Connection' cannot be created

    In case you wanted that to work, you'd have to set the aspcompat attribute in your page directive, and make sure that ADO's DLLs are present on the machine and registered.

    Although ADO.NET is what you should be using

  5. #5
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Re: 'ADODB.Connection' cannot be created

    I hope you didnt post the actual Username and Passwords you plan to use...

    Anjari

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width