OleDB Connection Command and Reader, complication on Making it work!

Posted on 2004-11-21
Medium Priority
Last Modified: 2012-08-13
Hi trying to Open a connection, Execute a select command and populate a datagrid with information from an access database.  The code compiles but I do not get any output.  All I have is one datagrid to be populated.  Please look at my code and let me know what I need to change or what I am doing wrong?  Thanks every1!

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="localhost.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            <script language="vb" runat="server">
            Sub Page_Load(Src As Object, E As EventArgs)
                  Dim LinksConnection As OleDBConnection
                  Dim LinksCommand As OleDbCommand
                  LinksConnection = New OleDbConnection  ("Provider=Microsoft.Jet.OleDB.4.0;server=localhost;uid=Admin;pwd=;database=C:\Inetpub\wwwRoot\Auto.mdb")
                  LinksCommand = New OleDBCommand("select * from Links", LinksConnection)
                  Dim dr As OleDBDataReader = LinksCommand.ExecuteReader()
                  dgLinks.DataSource = dr
            End Sub
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:datagrid id="dgLinks" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 72px" runat="server"
                        Height="336px" Width="368px"></asp:datagrid></form>
Question by:Petiedawgs
  • 6
  • 4
  • 2
  • +1

Assisted Solution

Joeisanerd earned 200 total points
ID: 12638505
the page load event never executes because you have told it to. Change your Page directive from AutoEventWireup=false to true  then it will fire on Page load

Accepted Solution

ryerras earned 1800 total points
ID: 12638778
You are doing couple of things wrong here. As Joeisanerd said, you have to put AutoEventWireup to true, but before that, you should change your page directive to the following

<%@ Page Language="vb" AutoEventWireup="true" >

Remember the directive you have is for a typical web form created by Visual Studio.NET. VS.NET uses code behind, but you are not using. So, your application will throw the following parse error message, since thats what you said, to look for the WebForm1 dll, which is generated by the vs.net, if you compile the project using vs.net with your original page directive.

Parser Error Message: Could not load type 'localhost.WebForm1'.

And you AutoEventWireup is important because, that tells your page to look for the typical event handlers for the page events automatically, since you are not wiring up any event handlers in your code

Author Comment

ID: 12639067
Alright I recieved an error now I am finally getting somewhere...here is the error.

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.Data.OleDb.OleDbException: Could not find installable ISAM.

Source Error:

Line 18:                   LinksConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDB.4.0;server=localhost;uid=Admin;pwd=;database=C:\Inetpub\wwwRoot\Auto.mdb")
Line 19:                   LinksCommand = New OleDBCommand("select * from Links", LinksConnection)
Line 20:                   LinksConnection.Open()
Line 21:                   
Line 22:                   Dim dr As OleDBDataReader = LinksCommand.ExecuteReader()
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 12639094
the error happens at the linksconnection.open()

Expert Comment

ID: 12639152
This error could be due to so many reasons. First I try to get tehe latest MDAC from microsoft. Then I look at the following article

Before all this if you do not have a password for your Admin account, please set it to empty string as follows

 LinksConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDB.4.0;server=localhost;uid=Admin;pwd='';database=C:\Inetpub\wwwRoot\Auto.mdb")

If none of this solves, I would go do some googling as this is a very common error

Author Comment

ID: 12639209
thanks im working on it!!!

Author Comment

ID: 12639221
Man I dont think im going to get too far in this....I have no registry entry for MS Jet 4.0.    I tried reinstalling MS Office to try and get that entry back but i dont have the cd for it.  Im basically stuck in a rock and a hard place.

Expert Comment

ID: 12639226
did you try putting blank empty string for pwd as i suggested

Author Comment

ID: 12639229
Im gonna let this one go and try some other options.  I am actually going to Reimage my computer right now and hope everything gets back in order.  Thanks ryerras and joeisanerd.  I think I can figure it out if i can get the MS Jet registry back in order.  

Author Comment

ID: 12639233
Yes I did  I put the blank password.

Expert Comment

ID: 12639236
ok good luck then. As soon as you finish figuring out, come back and close this question, or if you think any of our comments helped, close it right away, rather than leaving the question open forever

Expert Comment

ID: 12640918
If this is the only problem you are having I think reimaging your machine is bit extreme. Looking at your connection string it doesn't look right. Here is a connection string for accessing an access file that I know works

This is taken straight from a program I made and it's in C#
//Setup Ado connection to it
mdbConnString = "Provider=Microsoft.Jet.OLEDB.4.0;";
mdbConnString  += "Data Source="+openFileDialog1.FileName+";";
mdbConnString  += "Password=;User ID=Admin;Jet OLEDB:Database Password=;";
mdbConnString  += "Mode=Share Deny None;Jet OLEDB:Database Locking Mode=1;";

I don't believe that access needs the server= or the database= tag instead use Data Source=

Expert Comment

ID: 12809773

This may be cheating (but it works for me). Whenever I have a connection string problem, I let the IDE generate the connection string for me, then copy it into my code. Just setup a dummy connection using the ISE and then copy the connection string out of the connection's properties. At least this way you can test it and rule out whether the string itself is the issue.

Also, this won't help your error issue, but you can slightly optimize your code by cutting the datareader object out all together by assigning the LinksCommand.ExecuteReader directly to the dgLinks.DataSource parameter...

  dgLinks.DataSource = LinksCommand.ExecuteReader

At the very least, it's one less object to worry about...just my 2 cents!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question