以下代码正确读取本地计算机上的dbf文件,但是当部署到Windows Server 2012r2时,它会抛出异常:
错误[IM002] [Microsoft] [ODBC驱动程序管理器]数据源名称不是 找到并且没有指定默认驱动程序
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)
{
}
我发现服务器上没有安装任何odbc驱动程序,所以我安装了ODBC Driver 13 for SQL Server
但仍然遇到同样的错误。
答案 0 :(得分:1)
当启用应用程序池到32位应用程序时,它按照以下帖子运行:https://www.codeproject.com/Tips/305249/ERROR-IM-Microsoft-ODBC-Driver-Manager-Data-sou