CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Posts
    68

    Exception while connecting to Ms Access database

    When I connect to the Ms Access database from my Dot net application(VS 2005), I get an exception "System.IO.FileNotFoundException: Could not load file or assembly 'Interop.ADODB, Version=2.8.0.0". But the application and database is in the network. But for most of the systems it works. This exception is only for a few systems.

    The code to connect the database is follows

    Void ConnectDatabase()
    {
    MessageBox.Show("ConnectDatabase")
    Dim CnSt As String
    Dim Cn As OleDbConnection

    Dim Ta As New DataTable

    Dim database As ADOStruct
    database = New ADOStruct

    Dim sProvider As String

    sPathFileMitglied = sFilename

    Try
    sProvider = "Microsoft.Jet.Oledb.4.0"
    CnSt = "Provider=" & sProvider & ";Data Source=" & sFilename

    Cn = New OleDbConnection(CnSt)
    Cmd = Cn.CreateCommand()


    ' TODO: check, if database is not opened by other user
    conn = New ADODB.Connection
    conn.Provider = sProvider
    conn.ConnectionString = "Data Source = " & sFilename
    conn.CursorLocation = CursorLocationEnum.adUseClient
    conn.Mode = ConnectModeEnum.adModeReadWrite
    conn.Mode = ConnectModeEnum.adModeShareDenyNone
    conn.CursorLocation = CursorLocationEnum.adUseServer
    conn.Open()

    database.conn = conn

    ADO_OpenDatabase = database
    Catch ex As Exception
    ADO_OpenDatabase = Nothing
    MessageBox.Show("Exception while opening Database - " & ex.ToString(), "Error Opening Database", MessageBoxButtons.OK, MessageBoxIcon.Error)
    frmStart.WriteLog("modADO: ADO_OpenDatabase - Exception" + ex.ToString())
    End Try
    }





    From the from I am calling this method. The control even does not enter this function, I mean the message box is also not displayed. As soon as the function ConnectDatabase() is called, it hits an exception in the caller function in the main form. This looks strange for me as the application works properly for most of the systems in the organization. May be they have some different settings which restricts the connection to database. If some one knows this issue, please reply back. Thanks in advance.

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Exception while connecting to Ms Access database

    Thank you...

    This is much better...

    I have also answered you question in your original question here..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Exception while connecting to Ms Access database

    Victor Nijegorodov

  4. #4
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Talking Re: Exception while connecting to Ms Access database

    please always write code inside the code tags .
    Code:
    Void ConnectDatabase()
    {
    MessageBox.Show("ConnectDatabase")
    Dim CnSt As String
    Dim Cn As OleDbConnection
    
    Dim Ta As New DataTable
    
    Dim database As ADOStruct
    database = New ADOStruct
    
    Dim sProvider As String
    
    sPathFileMitglied = sFilename
    
    Try
    sProvider = "Microsoft.Jet.Oledb.4.0"
    CnSt = "Provider=" & sProvider & ";Data Source=" & sFilename
    
    Cn = New OleDbConnection(CnSt)
    Cmd = Cn.CreateCommand()
    
    
    ' TODO: check, if database is not opened by other user
    conn = New ADODB.Connection
    conn.Provider = sProvider
    conn.ConnectionString = "Data Source = " & sFilename
    conn.CursorLocation = CursorLocationEnum.adUseClient
    conn.Mode = ConnectModeEnum.adModeReadWrite
    conn.Mode = ConnectModeEnum.adModeShareDenyNone
    conn.CursorLocation = CursorLocationEnum.adUseServer
    conn.Open()
    
    database.conn = conn
    
    ADO_OpenDatabase = database
    Catch ex As Exception
    ADO_OpenDatabase = Nothing
    MessageBox.Show("Exception while opening Database - " & ex.ToString(), "Error Opening Database", MessageBoxButtons.OK, MessageBoxIcon.Error)
    frmStart.WriteLog("modADO: ADO_OpenDatabase - Exception" + ex.ToString())
    End Try
    }

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Exception while connecting to Ms Access database

    Quote Originally Posted by firoz.raj View Post
    please always write code inside the code tags .
    Agree!
    But note that it makes sense only if you place the formatted "code inside the code tags".
    Victor Nijegorodov

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

Featured