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

Posted on 2004-11-21
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="" 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
    LVL 9

    Assisted Solution

    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
    LVL 6

    Accepted Solution

    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, if you compile the project using 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

    Alright I recieved an error now I am finally getting 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()

    Author Comment

    the error happens at the
    LVL 6

    Expert Comment

    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;EN-US;283881

    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

    thanks im working on it!!!

    Author Comment

    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.
    LVL 6

    Expert Comment

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

    Author Comment

    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

    Yes I did  I put the blank password.
    LVL 6

    Expert Comment

    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
    LVL 9

    Expert Comment

    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=
    LVL 1

    Expert Comment


    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now