Hey guys,
I've been trying for days, but hvae not been successful in connecting
my database (Access) with my asp.net page. I have just figured out
more about ado.net, and tried copying several different sets of code,
but always at the dbconn.Open() line, the page fails. That is, if I
delete that line, an error does NOY occur. Even a simple code as
follows does not seem to work. The error says
"Server Error in '/' Application. Runtime Error". I have made sure the
database is under full control by 'everyone'.
<%@ Page Language="VB" EnableViewState="False" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.OleDb" %>
<script language="VB" runat="server">
Sub Page_Load
dim dbconnStr, sql As String
dbconnStr="Provider=Microsoft.Jet.OLEDB.4.0;"&"Data
Source=C:\Inetpub\wwwroot\Database_helvin\test.mdb;"
sql = "SELECT part_no FROM record"
dim dbconn As New System.Data.OleDb.OleDbConnection(dbconnStr)
dim cmd As New System.Data.OleDb.OleDbCommand(sql, dbconn)
dbconn.Open()
End Sub
</script>
<html>
<head>
<title>ASP.NET Simple Database Sample</title>
</head>
</html>
And again, for the following code, the same thing happens with the
line: mConnection.Open();
<%@ Page Language="C#" Debug="False" Explicit="True"%>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.OleDb" %>
<html>
<head>
<title>ADO.NET</title>
</head>
<script runat="server" language="C#">
void Page_Load (Object Source, EventArgs E) {
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=C:\Inetpub\wwwroot\opcm_pe
\database_helvin\test.mdb";
data_src.Text = strConnection;
string strSQL = "SELECT * FROM Record";
OleDbCommand mCommand = new OleDbCommand();
OleDbConnection mConnection=new OleDbConnection(strConnection);
mConnection.Open();
}
</script>
<body>
<h4>Reading data from the connection
<asp:label id="data_src" runat="server" /> to the DataGrid control.</
h4>
</body>
</html>
Does anyone have any idea why this is not working?
Thanks in advance!
Helvin