none
新人遇到老问题asp.net的excel导入sql权限问题,谢谢 RRS feed

  • 问题

  • 正在学习.net的菜鸟在学习过程中遇到一个老生常谈的问题,最近学习excel导入sql一段代码,用iis发布后,服务器本机可以,但是局域网其他客户端web访问导入不了数据,应该是权限问题,参考网上提出的各种解决方案还是不行,特来请教各位,谢谢

    系统:server 2008 x86

    数据库:sql2008 x86

    office:office2010 x86

    调试环境:vs2008

    代码:

    protected void Button1_Click(object sender, EventArgs e) { if (File1.PostedFile.ContentLength != 0) { //获得文件全名 string fileName = System.IO.Path.GetFileName(File1.PostedFile.FileName); //获得扩展名 string rightName = System.IO.Path.GetExtension(fileName); string str = Session["FjKey"].ToString(); if (!List.StrIFInStr(rightName, str)) { this.Response.Write("<script language=javascript>alert('导入人员错误!允许上传格式为" + Session["FjKey"].ToString() + "');</script>"); return; }//如果没有包含,就提示错误 try { Random g = new Random(); string rad = g.Next(100000).ToString(); string path = File1.Value.Replace("\\", "\\\\"); string sql_insert = "Select * INTO newtable" + rad + " FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source=" + path + ";User ID=Admin;Password=;Extended properties=Excel 5.0')...sheet1$"; List.ExeSql(sql_insert); string SQL_GetList1 = "select * from newtable" + rad + " "; OleDbDataReader NewReader = List.GetList(SQL_GetList1); while (NewReader.Read()) { Random g1 = new Random(); string rad1 = g1.Next(100000).ToString(); string numrad = "" + System.DateTime.Now.Year.ToString() + "" + System.DateTime.Now.Month.ToString() + "" + System.DateTime.Now.Day.ToString() + "" + System.DateTime.Now.Hour.ToString() + "" + System.DateTime.Now.Minute.ToString() + "" + System.DateTime.Now.Second.ToString() + "" + System.DateTime.Now.Millisecond.ToString() + "" + rad1 + ""; string SQL_GetLista = "select * from Staff where GongHao='" + NewReader["工号"].ToString() + "'"; OleDbDataReader NewReadera = List.GetList(SQL_GetLista); if (NewReadera.Read()) { string sql_insert1 = "insert into khb (Number,StaffId,StaffNumer,XingMing,XingBie,ShenFen,BuMenId,BuMen,GangWei,ZhiWu,KaoheLX,KaoheQJ,KaoheCJ,KaoheDJ,KaohePJ,PjPeople,Beizhu,KaoheSJ,Username,Realname,Unit,UnitId,Respon,ResponId,NowTimes) values ('" + numrad + "" + NewReadera["id"].ToString() + "" + NewReadera["GongHao"].ToString() + "','" + NewReadera["id"].ToString() + "','" + NewReadera["GongHao"].ToString() + "','" + NewReadera["XingMing"].ToString() + "','" + NewReadera["XingBie"].ToString() + "','" + NewReadera["ShenFen"].ToString() + "','" + NewReadera["YinPinBMId"].ToString() + "','" + NewReadera["YinPinBM"].ToString() + "','" + NewReadera["YinPinZW"].ToString() + "','" + NewReadera["ZhiWu"].ToString() + "','" + NewReader["考核类型"].ToString() + "','" + NewReader["考核期间"].ToString() + "','" + NewReader["考核成绩"].ToString() + "','" + NewReader["考核等级"].ToString() + "','" + NewReader["考核评价"].ToString() + "','" + NewReader["评价人"].ToString() + "','" + NewReader["备注"].ToString() + "','" + NewReader["考核时间"].ToString() + "','" + this.Session["Username"] + "','" + this.Session["Realname"] + "','" + this.Session["GzdwName"] + "','" + this.Session["GzdwId"] + "','" + this.Session["Respon"] + "','" + this.Session["ResponId"] + "','" + System.DateTime.Now.ToString() + "')"; List.ExeSql(sql_insert1); } NewReadera.Close(); } NewReader.Close(); string linsh = "drop table newtable" + rad + ""; List.ExeSql(linsh); this.Response.Write("<script language=javascript>alert('导入成功!');window.location.href='Uploadkhxx.aspx'</script>"); } catch { this.Response.Write("<script language=javascript>alert('导入数据失败!');</script>"); return; } } }

    在服务器上导入数据正常,在客户端导入就是导入数据失败!服务器可以执行,代码应该没有问题,烦请各位不吝赐教

    十分感谢

    我尝试过:

    1.修改com组件权限

    2.iis程序池设local system

    3.sql程序接口设置权限

    4.换成excel 12.0的字符串链接

    上述皆失败,方才寻得此地求助各位!再次感谢!



    2015年10月27日 7:09

全部回复