My project is to extract some attributes from a folder with .mdb to .csv files. All functions are processing properly but I have an issue with the ConnectionString.
When run for the first time, it opens the connection for the first file in folder and extracts the .csv file and closes the connection. All good so far.
Afterwards, when it goes for the second file in the folder, it somehow opens again the ConnectionString for the first file but the function calls the second .mdb file. How can I make it open the second file?
static void Main()
{
CreateFolder();
string dst_fld = @"C:\csv\AllCsvFiles";
string src_fld = @"C:\mdb";
string dst_ext = ".mdb";
string[] mdb_array = Directory.GetFiles(src_fld, "*" + dst_ext, SearchOption.TopDirectoryOnly); // Get all mdb files from a folder
OleDbConnection cn = new OleDbConnection();
foreach (string tname in mdb_array)
{
cn.ConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}",mdb_array);
try
{
cn.Open(); // open the connection
ExportFunction(cn, tname, dst_fld); // call function for export the csv file
}
finally
{
cn.Close();
}
}
GetCSVFiles();
DeleteFF();
}
cn.Open()executes for the second time?....0;Data Source={0}",mdb_array);instead ofmdb_array, you wanttnamehere i think?