VS运行程序就会报错,如果IIS发布就不会
因为需要跟踪,必须要用VS运行,程序和错误如下
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory
+ "UploadedFiles\\" + filename) == false)
{
throw new Exception("服务器目录找不到需要导入的文件");
}
DataTable dt = new DataTable();
string fileExtension = System.IO.Path.GetExtension(filename).ToLower();
try
{
OdbcConnection Connnection = new OdbcConnection();
String strExcelConn = "";
strExcelConn = "DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb);" +
"UID=admin;" +
"UserCommitSync=Yes;" +
"Threads=3;" +
"SafeTransactions=0;" +
"ReadOnly=1;" +
"PageTimeout=5;" +
"MaxScanRows=8;" +
"MaxBufferSize=2048;" +
"FIL=excel 12.0;" +
"DriverId=1046;" +
"DBQ=" + AppDomain.CurrentDomain.BaseDirectory + "UploadedFiles\\" + filename;
Connnection.ConnectionString = strExcelConn;
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = Connnection;
cmd.CommandText = "SELECT * FROM [SHEET1$]";
Connnection.Open();
OdbcDataAdapter oda = new OdbcDataAdapter(cmd);
oda.Fill(dt);
Connnection.Close();
}
catch (Exception ex)
{
throw ex;
//throw new Exception("无法读取表格数据");
}