Why does the following code gives error when it is published and browsed from IIS?

0
private DataTable LoadCSV()
{
    DataSet ds = new DataSet();
    try
    {

        string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + this.DirectoryPathCSV.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
        string sql_select;

        OdbcConnection conn = new OdbcConnection(strConnString.Trim());
        conn.Open();

        sql_select = "select * from [" + this.FilePathCSV.Trim() + "]";
        OdbcDataAdapter obj_oledb_da = new OdbcDataAdapter(sql_select, conn);

        obj_oledb_da.Fill(ds, "csv");
        conn.Close();
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return ds.Tables[0];
}

The above code reads the .CSV file and returns the file as DataTable. It runs well in Visual Studio 2010 but it is giving an exception when i publish this in IIS and browse from IIS. And the Error is like

System.Data.Odbc.OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.Odbc.OdbcConnection.Open()

I tried possible ways to find the cause but failed, Any help would be appreciated greatly.

c#
asp.net
csv
iis
odbc
asked on Stack Overflow Jul 29, 2014 by SaiKiran Mandhala • edited Jul 31, 2014 by Quentin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0