sadier

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
第三天了,总于解决了
是web.config中的一句话去掉就行了
    <identity impersonate="true"/>

代码不能运行产生问题:
我的机子上可以,服务器不能运行。现象是oledb不能Open();总是出错

贴出代码:
        private void SaveToExcel()
        
{

            
string urlPath = HttpContext.Current.Request.ApplicationPath + "/Temp/";

            
string physicPath = HttpContext.Current.Server.MapPath(urlPath);

            
string fileName = Guid.NewGuid() + ".Xls"

            
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + physicPath + fileName +";Extended Properties=Excel 8.0;";

            OleDbConnection objConn 
= new OleDbConnection(connString);
            OleDbCommand objCmd 
= new OleDbCommand();
            objCmd.Connection 
= objConn;
            objConn.Open();



            
//建立表结构

            objCmd.CommandText 
= @"CREATE TABLE TBL_Customer (CustomerName varchar,CustomerNo varchar)";

            objCmd.ExecuteNonQuery();

            objCmd.CommandText 
= "INSERT INTO TBL_Customer(CustomerName, CustomerNo) VALUES ('毛小华', 'good')";

            objCmd.ExecuteNonQuery();

            
//提供下载

            objCmd.Dispose();
            objConn.Dispose();
            

            HttpResponse response 
= HttpContext.Current.Response; 
            response.Clear();
            response.WriteFile(physicPath 
+ fileName);
            
string httpHeader="attachment;filename=backup.Xls";
            response.AppendHeader(
"Content-Disposition", httpHeader);
            response.Flush();

            System.IO.File.Delete(physicPath 
+ fileName);//删除临时文件
            response.End();        
        
        }


        
private void Button1_Click(object sender, System.EventArgs e)
        
{
            
//StartOutPort();
            
            SaveToExcel();
        }


处理步骤,查了很多文章,做了很多步骤:
1、怀疑权限,把Temp的权限设置了完全,不行!
2、怀疑mdac,jet等engine有问提,就重装了,不行!
3、索性sql sp3, 和 window  sp4, 等所有可安装的补丁重新装一边,还是不行。
4、有说IIS, 和匡架有可能,就把iis和frame work 1.1都重新安装了一边,还是不行,。
5、郁闷,睡觉了再想,重新建新工程 , 哈哈 ok, 拷入旧ws.config  出错。
呵呵,一个一个比较,就得到    <identity impersonate="true"/>是有问题的。

总结:
我的机子是fat32的权限要求不高 能够运行。
服务器是ntfs的权限要求高,
posted on 2006-01-03 14:06  毛小华  阅读(1572)  评论(1编辑  收藏  举报