0

Referring to this question, I figured out how open and connect to a single mdb file. At the moment I am doing:

String accessConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;
                                 Data Source=C:\MyMDB\MyMDBFile.mdb; 
                                 Persist Security Info = False; ";
using (OleDbConnection accessConnection = new OleDbConnection(accessConnectionString))
      {
           ReadContent(); 
      }

But I want to open multiple files from the directory, basically I want to:

String[] mdbFiles = Directory.GetFiles(@"C:\MyMDB\", "*.mdb");  

And use this in the accessConnectionString

I know it should be something like,

foreach (var filePath in mdbFiles)
        {
             accessConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" 
             + "Data Source=" + filePath + " Persist Security Info = False; ";
        }

But is this the only way to access multiple mdb files?

Community
  • 1
  • 1
agenthost
  • 748
  • 2
  • 9
  • 24
  • 2
    First, your code doesn't open anything and because you reset the variable accessConnectionString at every loop you end up with a connectionstring only for the last file in the folder. Second, the connection string serves as input to the OleDbConnection object and this object handles only one connection at a time. You need multiple OleDbConnection one for each file you intend to work with – Steve Jun 10 '16 at 09:30
  • Can you explain what is the purpose of these files and why you need them opened simultaneously? – Steve Jun 10 '16 at 09:31
  • 1
    have a List of connections, and do a foreach *.mdb, list.Add(new Oledbconnection(connectstring with that mdb in it) – BugFinder Jun 10 '16 at 09:33
  • Thanks for your answers, I have more clarity now! – agenthost Jun 10 '16 at 09:40

0 Answers0