error while reading Excel sheet
I have code to read Excel from c3 language :
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 Od开发者_高级运维bcCommand();
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. Wherere as it is running fine locally.
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
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
You're trying to reference a DSN that hasn't been created yet it seems. You can create one of these by opening your Administrative Tools
folder and then starting the Data Sources (ODBC)
applet.
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.
You could do it the DSNless way by providing a path to the file. see this post:
http://weblogs.asp.net/rajbk/archive/2009/05/02/uploading-an-excel-file-to-sql-through-an-asp-net-webform.aspx
精彩评论