惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
博客园 - 三生石上(FineUI控件)
博客园_首页
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
GbyAI
GbyAI
M
MIT News - Artificial intelligence
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
Recent Announcements
Recent Announcements
小众软件
小众软件
量子位
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏

博客园 - 毛小华

如果数据库的处理(逗号) 今天碰到了http/1.1 403 Forbidden错误,处理如下 防止多次提交的几个比较 - 毛小华 - 博客园 SQL server 产生按日期排序的编号 sql数据库的连接的一句话(今天花了一个小时想明白的就记下来了) 一棵树 Bom树 一个自己测试通过的操作EXCEL 一个自己测试通过的发邮件操作 - 毛小华 - 博客园 控制界面是否可输入的一个例子 - 毛小华 - 博客园 今天电脑中毒了 WebPanelBar的使用 AlertButton 一个经验 一些感觉。 sql 语句中where条件和jion on条件的区别 asp.net 的经验 出现怪事啦,大家看啦 erp的设计经验 如果输入的dll名字被改后应该手工删除dll
一个很简单的操作excel的例子 - 毛小华 - 博客园
毛小华 · 2006-01-03 · via 博客园 - 毛小华

第三天了,总于解决了
是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的权限要求高,