|
-
Jul 12th, 2005, 04:18 PM
#1
Thread Starter
Junior Member
Error Message in Database Connection
I’m trying to create the simplest database retrieval. However, I keep getting errors.
HTML Code:
<%@ LANGUAGE="VBScript" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%
Dim Connection
Dim RS
Dim SQLStmt
Dim SSN, Firstname, Lastname
Dim connect_string
Dim dbConn
' this code opens the database
connect_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=employee.mdb;"
dbConn = server.createObject("ADODB.connection")
dbConn.open (connect_string)
%>
<html>
<head>
<title>WebForm5</title>
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
</body>
</html>
My Error message. What does it mean? How can I correct this?
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 18: ' this code opens the database
Line 19: connect_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=employee.mdb;"
Line 20: dbConn = server.createObject("ADODB.connection")
Line 21: dbConn.open (connect_string)
Any help would be appreciated
Thanks
-
Jul 13th, 2005, 01:23 AM
#2
Re: Error Message in Database Connection
Why are you using ASP code in an ASP.NET page?
-
Jul 13th, 2005, 01:25 AM
#3
Re: Error Message in Database Connection
.NET allows you to work with ADO.NET. You don't need to use ADODB anymore. Perhaps a quick tutorial would help:
http://samples.gotdotnet.com/quickstart/aspplus/
-
Jul 13th, 2005, 09:27 AM
#4
Thread Starter
Junior Member
Re: Error Message in Database Connection
Thank you very much for the tutorial page:
http://samples.gotdotnet.com/quickstart/aspplus/
Great Tutorial Page, Thanks
But of course I'm running into problems. I can't seem to get the connection string to work. I typed in their sample code, however I always get confused with the connection string, any connection string.
Here's their sample code:
Code:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<HEAD>
<% 'http://samples.gotdotnet.com/quickstart/aspplus/ %>
<LINK href="intro.css" rel="stylesheet">
<script language="VB" runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_scratch.mdb;")
MyCommand = New SqlDataAdapter("Select * from scratch where type='" + Category.SelectedItem.Value + "'", myConnection)
DS = new DataSet()
MyCommand.Fill(DS, "Scratch")
MyList.DataSource = DS.Tables("Scratch").DefaultView
MyList.DataBind()
End Sub
</script>
</HEAD>
<body>
<center>
<form id="Form1" action="webform6.aspx" method="post" runat="server">
<asp:adrotator id="Adrotator1" runat="server" NAME="Adrotator1" BorderWidth="1" BorderColor="black"
AdvertisementFile="ads.xml"></asp:adrotator>
<h3>
Name:
<asp:textbox id="Name" runat="server" />
Category:
<asp:dropdownlist id="Category" runat="server">
<asp:listitem>psychology</asp:listitem>
<asp:listitem>business</asp:listitem>
<asp:listitem>popular_comp</asp:listitem>
<asp:listitem>crazy_walk</asp:listitem>
<asp:listitem>Thursday</asp:listitem>
<asp:listitem>writers_cramp</asp:listitem>
</asp:dropdownlist>
</h3>
<asp:button text="Lookup" OnClick="SubmitBtn_Click" runat="server" ID="Button1" NAME="Button1" />
<p>
<ASP:DataGrid id="MyList" HeaderStyle-BackColor="#aaaadd" BackColor="#ccccff" runat="server" />
</form>
</center>
</P>
</body>
</HTML>
I had to change the connection string. Their's was pointing to their server.
Here's my error message:
Code:
Keyword not supported: 'provider'.
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.ArgumentException: Keyword not supported: 'provider'.
Source Error:
Line 13: Dim MyCommand As SqlDataAdapter
Line 14:
Line 15: MyConnection = New SqlConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_scratch.mdb;")
Line 16: MyCommand = New SqlDataAdapter("Select * from scratch where type='" + Category.SelectedItem.Value + "'", myConnection)
Line 17:
I'm using Visual Basic .NET standard 2003.
Any help would be appreciated.
Thanks
-
Jul 13th, 2005, 09:40 AM
#5
Re: Error Message in Database Connection
That's because you're using a SQLConnection object, but giving it a connection string for an MS Access database. If you want to use your MDB file, then you should use the System.Data.Oledb namespace. That means you'll be using the OleDbDataAdapter and the OleDbConnection objects.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|