关于Microsoft Jet 数据库引擎打不开文件的问题,求教!

Yolanda_WJ 2017-03-01 05:06:14
近期遇到一个问题,用OleDbConnection的时候打开失败,但不是次次报错,没有规律,在服务器用一阵儿后就会报错,如下
这时候清一遍程序池之后,又可以正常运行了,请问这是什么问题,求解答,谢谢!!!
ps:在网上查类似的问题,都是说权限之类的问题。这个应该不是,因为平常是可以正常运行的。代码附上:
//先上传至服务器再获取Excel文件
HttpPostedFile spFile = SelFile.PostedFile; //对文件进行操作的对象
string qz = spFile.FileName.Substring(spFile.FileName.LastIndexOf("\\")+1);
string spPath = Server.MapPath("..//FilePath//ImportExcel");
string spValue = DateTime.Now.ToString("yyyyMMddHHmmss") + qz.Trim();
spFile.SaveAs(spPath.Trim() + "\\" + spValue.Trim());
string mystring = "";
if (drdw_Edition.SelectedItem.Text.Trim() == "2003")
{
mystring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + spPath.Trim() + "\\" + spValue.Trim() + "';Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\""; //for excel 2003
}
else
{
mystring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + spPath.Trim() + "\\" + spValue.Trim() + "';Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\""; //for excel 2007
}
OleDbConnection cnnxls = new OleDbConnection(mystring);
try
{
cnnxls.Open();
DataSet dss = new DataSet();
try
{
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$] ", cnnxls); //从EXCEL表中获取数据
myDa.Fill(dss); //填充数据源
ds = dss;
if (ds != null)
{
dg_List.Visible = true;
dg_List.DataBind();
}
}
catch
{
Response.Write("<script>alert('Excel格式不正确,请检查列名称和表名称是否正确!');</script>");
}
}
catch(Exception ex)
{
Response.Write("<script>alert('" + ex.Message.Replace("'","").Trim() + "!');</script>");
}
finally
{
cnnxls.Close();
cnnxls.Dispose();
}
...全文
279 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧