Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I'm trying to connect Ms-Access from c#, but it's returning an error.

Can you tell me where I went wrong?

C#
connection_string = @"Provider=Microsoft.ACE.OLEDB.12.0;password=pass@word1;Data Source=C:\Users\bojjaiah\Documents\bojjaiah\Databases\college.accdb;";


error:

Cannot start your application. The workgroup information file is missing or opened exclusively by another user

thanks in advance.
Posted
Updated 16-Mar-19 4:44am

This error is caused by 2 reasons in my opinion
------------------------------------------------
1. Using ODBC password formatted connection string instead of the OleBD formatted connection string.

ODBC
DSN=Organization_DB;dbq=C:\DATAFOLDER\MNI\mnitest\Org_Client_DB.accdb;driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin;Pwd=xxxxxxxx}

Equivalent OleDB
Provider=Microsoft.ACE.OLEDB.15.0;Data Source=C:\DATAFOLDER\MNI\mnitest\Org_Client_DB.accdb;User ID=admin;Jet OLEDB:Encrypt Database=True;Jet OLEDB:Database Password=xxxxxxxx"

2. If the database is encypted using 2010-2013 format, set the encryption flag in the connection string
Jet OLEDB:Encrypt Database=True;

------------------------------------------------
After, this the connection should work just fine.

This is what worked for me.
 
Share this answer
 
In addition you need to instanciate Commands, Adaptors and Connections from the correct namespace Data.OleDb
See extracts from a working solution below ( .. not a complete class)


Public Class ClientLogicOdbc
    Private DataBaseMessage As String
	Private CmdConnect As System.Data.OleDb.OleDbConnection
    Private CmdKPIList As System.Data.OleDb.OleDbCommand
    Private DaTable As System.Data.OleDb.OleDbDataAdapter
	Private TbKPIList As New System.Data.DataTable
    Private TbKPIRow As System.Data.DataRow
	
	Public Sub New()
      Client_Data_Logged = New ClientData
      DbConnectivity = DatabaseConnectivity.NotConnected
      ConnString = ReadConnectionSetting("CompanyConnectionOleDb")   
	  Call Connect()	  
    End Sub
	
	Private Sub Connect()
      Try
        CmdConnect = New System.Data.OleDb.OleDbConnection(ConnString)
        CmdKPIList = New System.Data.OleDb.OleDbCommand()
        CmdConnect.ConnectionString = ConnString
        CmdConnect.Open()
        DbConnectivity = DatabaseConnectivity.Connected
      Catch ex As Exception
        Me.LocalException = ex        
        Call RaiseErrorMessage(ex.Message, ex)
        DbConnectivity = DatabaseConnectivity.Faulted
        Debug.Print(ex.Message)
      End Try
    End Sub
	
	Public Function Company_File_Exists(ByVal ReportListing As ClientData) As Boolean
      Dim Found As Boolean = False
      Dim DatabaseMessage As String
      TbKPIList = New Data.DataTable
      If DbConnectivity = DatabaseConnectivity.Connected Then
        Try
          DatabaseMessage = "Select dbo_Company_Files.Imported From dbo_Company_Files where dbo_Company_Files.Filename='" & ReportListing.name & "' and dbo_Company_Files.startTime=#" & ReportListing.startTime.ToString("yyyy-MM-dd hh:mm:ss") & "# and dbo_Company_Files.EndTime=#" & ReportListing.endTime.ToString("yyyy-MM-dd hh:mm:ss") & "# ;"
          DaTable = New Data.OleDb.OleDbDataAdapter(DatabaseMessage, CmdConnect)
          DaTable.Fill(TbKPIList)
          TbKPIList.TableName = "dbo_Company_Files"

          If TbKPIList.Rows.Count > 0 Then
            Found = True
          End If
        Catch ex As Exception
          LocalException = ex
        Finally
          If Not TbKPIList Is Nothing Then
            TbKPIList.Clear()
            TbKPIList = Nothing
          End If
          If Not DaTable Is Nothing Then
            DaTable.Dispose()
            DaTable = Nothing
          End If
        End Try
      End If
      Return Found
    End Function
	
	
	Public Function ReadConnectionSetting(ByVal key As String) As String
      Dim result As String = ""
      Dim ConnStringSetting As System.Configuration.ConnectionStringSettings
      Try
        Dim app_Conn_Settings As System.Configuration.ConnectionStringSettingsCollection =
             System.Configuration.ConfigurationManager.ConnectionStrings

        ConnStringSetting = app_Conn_Settings(key)
        If IsNothing(ConnStringSetting) Then
          result = ""
        Else
          result = ConnStringSetting.ConnectionString
        End If
        
      Catch ex As System.Configuration.ConfigurationErrorsException

      End Try
      Return result
    End Function
	
End Class
 
Share this answer
 
Comments
CHill60 18-Mar-19 7:24am    
Are you aware that you can add information to your post by using the "Improve solution" link on your solution. This is the preferred approach rather than posting multiple solutions to one question (which can be confusing if one is up/downvoted and they appear out of sequence)
I had this issue and the fix was simple. Just compact and repair your database. I use Access 2013 Pro. Then try again. It worked for me. It seems there was an internal DB issue that got resolved using this method.
 
Share this answer
 
Comments
OriginalGriff 13-Oct-20 7:47am    
While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 8 year old ones. After that amount of time, it's unlikely that the original poster is at all interested in the problem any more!
Answering old questions can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.
CHill60 13-Oct-20 8:09am    
But a year ago you had two different solutions that also allegedly worked! Rather than posting conflicting solutions you should use the "Improve solution" link on your original solution to provide any updates - as I said back in March 2019

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900