Results 1 to 7 of 7

Thread: beginner's question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320

    beginner's question

    I'm trying to connect to database using a ASP.NET Web Application.
    I drag and drop an OleDbConnection control and then import files,
    provide the connection string and test connection to Access NWIND.mdb

    Imports System
    Imports System.Data
    Imports System.Data.Common
    Imports System.Data.OleDb

    then in the page_load event

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    Try
    OleDbConnection1.Open()
    Response.Write("Success")
    Catch dbException As OleDbException
    Response.Write("Unable to open database")
    End Try
    End Sub

    It says Unable to open database.

    Whereas I do the same steps in Windows application it gets connected to the same database just fine.
    I can't figureout what am I doing wrong?

  2. #2
    New Member
    Join Date
    Mar 2002
    Posts
    13
    i think u are missing some lines of code. u need to look not only in ur form_load sub. Search after e.g. OleDbConnection1 declaration maybe at the top somewhere...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320
    Well here is the whole code, when I debug it it first goes to page_init, executes the line initialize_component but I don't see it going to it then goes to try_catch and fails there.Please suggest:

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Data
    Imports System.Data.Common
    Imports System.Data.OleDb


    Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection()
    '
    'OleDbConnection1
    '
    Me.OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Inetpub" & _
    "\wwwroot\Database\NWIND.MDB;Mode=Share Deny None;Extended Properties="""";Jet OLED" & _
    "B:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDBatabase Password="""";J" & _
    "et OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partia" & _
    "l Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Passwor" & _
    "d="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet" & _
    " OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repa" & _
    "ir=False;Jet OLEDB:SFP=False"

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    Try
    OleDbConnection1.Open()
    Response.Write("Success")
    Catch dbException As OleDbException
    Response.Write("Unable to open database")
    End Try
    End Sub

    End Class

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320
    I'm track the error and I get
    The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\Database\login.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

    Whereas if I try to open it with VB.NET application it opens just fine!

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Make sure the directory contaning the access file has read access and is granted to the ASPNET account.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    320
    I tried it in the same directory under wwwroot and also ouside it.
    The directory is not read only. Also pleae explain what do you mean by 'and is granted to the ASPNET account'

  7. #7
    New Member
    Join Date
    Mar 2002
    Posts
    13
    try using this connectionstring for ur db:

    Code:
    "Provider=Microsoft.Jet.OLEDB.4.0; data source=" & C:\Inetpub" & _
    "\wwwroot\Database\NWIND.MDB"
    or just remove that "Mode=Share Deny None" thing, maybe that works also, or find some other proberty for that mode.

    one more thing, u could write in ur try catch code not only "Unable to open database" evenmore u could use "dbException.message" that will return the exactly errormessage. And dont forget to close ur dbconnection when u finished with ur access to it.


    greetings

    p.s.: if u restart ur iis it should work again too, but u should do this only on ur local machine ^^
    Last edited by PJ6; Nov 11th, 2003 at 03:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width