Hi, for some reason I can read this file perfectly on my machine (.net framework 4.5 is installed)
But when I run it on one of the servers (.net framework 4.0 is installed), i can't get the file to even open.
try
{
// Connect to the file with the clean data and extract the relevant information
using (OleDbConnection con =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + CardFileGeneratorOutput.ToString() + ";"
+ "Extended Properties='text;HDR=Yes;FMT=Delimited(,)';"))
{
using (OleDbCommand cmd = new OleDbCommand(string.Format
("SELECT VisaMasterNbr, AmexNbr FROM " + CleanedNedAllTermFile.ToString() + ""), con))
{
try
{
con.Open();
}
catch (Exception e) { Console.WriteLine("Error reading from {0}. Message = {1}", @"C:\alienoreports\3.txt", e.Message); }
// Bind data to tbl(datatable), store all data in a list using Lambda Expressions, write data to a new CSV file.
using (OleDbDataAdapter adp = new OleDbDataAdapter(cmd))
{
using (DataTable tbl = new DataTable("MyTable"))
{
adp.Fill(tbl); // bind data to a datatable to keep it in memory for faster execution/processing
List<string> VisaMasterNbr = tbl.AsEnumerable().Select(x => x[0].ToString().PadLeft(10, '0')).ToList();// pad values and store it in a list
List<string> AmexNbr = tbl.AsEnumerable().Select(x => x[1].ToString().PadLeft(10, '0')).ToList();// pad values and store it in a list
index = 0;
StringBuilder sb = new StringBuilder();
foreach (string part in VisaMasterNbr)
{// write the relevant information to a result file.
sb.Append(VisaMasterNbr[index] + ',' + AmexNbr[index] + Environment.NewLine);
index++;
}
File.WriteAllText(VisaMasterAmexNumbers.ToString(), sb.ToString());
}
}
}