'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
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.
Re: 'ADODB.Connection' cannot be created
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
Re: 'ADODB.Connection' cannot be created
I hope you didnt post the actual Username and Passwords ;) you plan to use...
Anjari