locked
can't show data from an Access DB 2010 in ASP.NET VB RRS feed

  • Question

  • User651828378 posted

    Hi.

    Im coding in my sparetime so dont know whats wrong in this code, hope someone can help me..

    I have an Access DB called webtest.accdb it's in my VS2010 project, in the folder App_Data

    When im running my script i get this error, Compiler Error Message: BC30451.

    http://imageshack.us/f/90/error1nv.png/

     

    My code is as follows..
    .:Web.Config:.

    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
      <appSettings/>
      <connectionStrings>
        <add name="ConnectionString1" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\webtest.accdb;Persist Security Info=False;"/>
        <!--<add name="ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\web\localuser\ditdomæne.dk\database\webtest.accdb"/>-->
      </connectionStrings>
        <system.web>
            <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
        </system.web>
    
    </configuration>

    .:Default.aspx:.

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Access2010_Connection_VIRKER._Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">

    <title></title></head>

    <body>

    <form id="form1" runat="server">

    <div>

    <% Call OpenDB()%>

    </div>

    </form>

    </body></html>

    .:Default.aspx.vb:.

    Imports System.Data
    Imports System.Data.OleDb
    Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Public Sub OpenDB()
    Dim ObjConn As OleDbConnection
    Dim ObjCmd As OleDbCommand
    Dim ObjReader As OleDbDataReader
    'ConnectionString og SQL linje.
    Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
    ObjConn = New OleDbConnection(ConnectionString)
    ObjCmd = New OleDbCommand("SELECT * FROM Tabelnavn1 ORDER BY Id DESC;", ObjConn)
    'Prøv at åben Connection.
    Try
    ObjConn.Open()
    ObjReader = ObjCmd.ExecuteReader(CommandBehavior.CloseConnection)
    'Hvis der er data, udskriv da dataen.
    If ObjReader.HasRows() Then
    Dim StrCountGuestB As String
    Response.Write("<table style=""width:340px; border:0px;""><tr>")
    Do While ObjReader.Read()
    Response.Write("<td>" & ObjReader("Id") & "</td>")
    Response.Write("</tr><tr>")
    Response.Write("<td>" & ObjReader("Title") & "</td>")
    Response.Write("</tr><tr>")
    Response.Write("<td>" & ObjReader("Beskrivelse") & "</td>")
    Loop
    Response.Write("</tr></table>")
    Else
    'Hvis der ikke er data, lav en fejl tekst.
    Response.Write("Der er ikke skrevet i databasen.")
    End If
    Catch ex As Exception
    Console.WriteLine(ex.Message)
    Finally
    If Not ObjReader Is Nothing Then
    ObjReader.Dispose()
    End If
    If Not ObjConn Is Nothing Then
    ObjConn.Dispose()
    End If
    End Try
    End SubEnd Class

    Hope u can help me....
    Thx

    Friday, May 20, 2011 12:28 PM

Answers

  • User3866881 posted

    Blank site? Oh no……

    You should first try to remove "try……catch……finally"block, and then debug your app, I suspect whether there's something wrong with your sqlconnection or sqlcommand.

    And please make sure that you really have data contents in your table.

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2011 8:56 PM

All replies

  • User1867929564 posted

    According to http://www.connectionstrings.com/access-2007
    your connection code appear to be ok in config file.I suggest you to remove the comment one.
    just include providerName="System.Data.OleDb" 


    when you put breakpoint then error is throwing in which line.

    http://forums.asp.net/t/936107.aspx/1
     

    Does it build ok.Is dll being created in bin  ? 

    Saturday, May 21, 2011 2:26 AM
  • User3866881 posted

    Hello:)

    If your logic codes are right, and please try the following things:

    1) Just call <%OpenDB()%>, don't add Call again.

    2) Please call the method directly in the page_Load

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

     If Not IsPostBack Then
     
              OpenDB()

     End If  
    End Sub 

    Sunday, May 22, 2011 10:41 PM
  • User651828378 posted

    Hi

    i now get a blank site with the call in Page_Load, but no data at all..
    Why dont it make the Response.Write code !?
    I have deleted the Call OpenDB from the default.aspx site.

    Monday, May 23, 2011 2:03 PM
  • User3866881 posted

    Blank site? Oh no……

    You should first try to remove "try……catch……finally"block, and then debug your app, I suspect whether there's something wrong with your sqlconnection or sqlcommand.

    And please make sure that you really have data contents in your table.

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2011 8:56 PM