The below code reads dbf files on local machine correctly, but when deployed to Windows server 2012r2, it throws exception:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
try
{
OdbcConnection obdcconn = new OdbcConnection();
//obdcconn.ConnectionString = "Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=" + strTempDirectory + "\\;Exclusive=No; NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
obdcconn.ConnectionString = "Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=" + strTempDirectory + "\\";
obdcconn.Open();
System.Data.Odbc.OdbcCommand oCmd = obdcconn.CreateCommand();
oCmd.CommandText = "SELECT * FROM " + Path.Combine(strTempDirectory, tempFileName); // Specify full path including dbf filename with extension
AVSNAssignmentDetails = new DataTable();
AVSNAssignmentDetails.Load(oCmd.ExecuteReader());
obdcconn.Close();
ErrorLogger.LogActivity(string.Format("\t - Dbf data retrived successfully for file {0} of ClaimNumber: {1}", fileInfo.Name, _strClaimNumber), _strActivityLogFileName);
}
catch (Exception ex)
{
}
I found that no odbc driver was installed on the server, so I installed ODBC Driver 13 for SQL Server
but still getting the same error.