注册 登录
编程论坛 ASP.NET技术论坛

ado.net数据库连接

isolated 发布于 2011-06-05 17:04, 562 次点击
紧急求助程序连接sqlserver2000数据库出现问题
    服务器配置:
    windowsxp
    framework2.0
    sqlserver2000
    出现如下错误:
    An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (PRovider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
    检查后发现是webconfig的配置问题,将server=local,改成本地计算机名,问题解决。
3 回复
#2
isolated2011-06-05 17:04
    经常需要在数据库与Execl之间互导数据。net时代,可以使用使用Microsoft.Jet.OleDb访问访问Excel,网上已经有很多类似的资源,最典型也是最简单的可能如下:(环境)
    // 连接字符串
    string xlsPath = Server.MapPath("~/app_data/somefile.xls"); // 绝对物理路径
    string connStr = "PRovider=Microsoft.Jet.OLEDB.4.0;" +
    "Extended Properties=Excel 8.0;" +
    "data source=" + xlsPath;
    // 查询语句
    string sql = "SELECT * FROM [Sheet1$]";
    DataSet ds = new DataSet();
    OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);
    da.Fill(ds);    // 填充DataSet
    // 在这里对DataSet中的数据进行操作
    // 输出,绑定数据
    GridView1.DataSource = ds.Tables[0];
    GridView1.DataBind();
    很简单吧?!一切就像操作数据库一样,只是需要注意的是:
    1。数据提供程序使用Jet,同时需要指定Extended Properties 关键字设置 Excel 特定的属性,不同版本的Excel对应不同的属性值:用于 Extended Properties 值的有效 Excel 版本。
    对于 Microsoft Excel 8.0 (97)、9.0 (2000) 和 10.0 (2002) 工作簿,请使用 Excel 8.0。
    对于 Microsoft Excel 5.0 和 7.0 (95) 工作簿,请使用 Excel 5.0。
    对于 Microsoft Excel 4.0 工作簿,请使用 Excel 4.0。
    对于 Microsoft Excel 3.0 工作簿,请使用 Excel 3.0。
    ref:http://msdn.*url=/library/CHS/dv_vbcode/html/vbtskcodeexamplereadingexceldataintodataset.asp
#3
tw9202172011-06-08 17:08
傻傻的飘过..... 额. 没看懂,我写.net和Delphi的
#4
冰镇柠檬汁儿2011-06-09 10:06
楼主写的Excel的连接方法在网上很难找到的,当年我为了这个方法研究了很久,后来总结了一个类,这个方式确实很不错,能将数据导出成标准的excel格式,并且这个excel还能作为数据源使用,和其他的导出到excel方式相比,这个是最好的。
1