简体   繁体   English

读取Excel工作表时出错

[英]error while reading Excel sheet

I have code to read Excel from c3 language : 我有从c3语言读取Excel的代码:

DataTable dtChildrenData = new DataTable();
            OdbcConnection oConn = null;
            try
            {
                if (File.Exists(strSheetPath))
                {
                    oConn = new OdbcConnection();
                    oConn.ConnectionString = @"DSN=Excel Files;DBQ=" + strSheetPath + @";DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;PageTimeout=5;";

                    OdbcCommand oComm = new OdbcCommand();
                    oComm.Connection = oConn;
                    oComm.CommandText = "Select * From [Sheet1$]";

                    DataSet ds = new DataSet();
                    OdbcDataAdapter oAdapter = new OdbcDataAdapter(oComm);
                    oConn.Open();
                    oAdapter.Fill(ds);
                    dtChildrenData = ds.Tables[0];
                }
            }
            finally
            {
                oConn.Close();
            }
            return dtChildrenData;

But getting this error when i deploy the web application on IIS. 但是当我在IIS上部署Web应用程序时出现此错误 Wherere as it is running fine locally. 哪里,它在本地运行良好。

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ERROR [IM002] [微软] [ODBC驱动程序管理器]数据源名称未找到和指定默认驱动程序

How to solve this. 如何解决这个问题。 Please let me know if any information required to answer this question (about configuration) 请让我知道是否需要任何信息来回答这个问题(关于配置)

Remember it is running perfect locally from VS, when i deploying on IIS on same machine it giving error 记住,当我在同一台机器上的IIS上部署时,它在VS本地运行完美,这给了错误

You're trying to reference a DSN that hasn't been created yet it seems. 您正在尝试引用似乎尚未创建的DSN。 You can create one of these by opening your Administrative Tools folder and then starting the Data Sources (ODBC) applet. 您可以通过打开Administrative Tools文件夹,然后启动Data Sources (ODBC)小程序来创建其中之一。
It seems like you'll then have to create a DSN called Excel Files , if you have a machine where this currently works you might be able to copy the settings from that machine. 看来您随后必须创建一个称为Excel Files的DSN,如果您有一台目前可以在其中运行的计算机,则可以从该计算机复制设置。

You could do it the DSNless way by providing a path to the file. 您可以通过提供文件路径来以DSNless方式进行操作。 see this post: 看到这篇文章:

http://weblogs.asp.net/rajbk/archive/2009/05/02/uploading-an-excel-file-to-sql-through-an-asp-net-webform.aspx http://weblogs.asp.net/rajbk/archive/2009/05/02/uploading-an-excel-file-to-sql-through-an-asp-net-webform.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM