none
Problem while filling the dataset where the data source is a .CSV file RRS feed

  • Question

  • HI,
    I am trying to reading a .csv file from a remote desktop.

     

    the connection string that i am using is as follows:

     

    strConn = "Provider=MS Remote;"+"Remote Server=//<ComputerName>/<FolederName>;" + " Remote Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+@"d:/trial/try1.csv"+";"+"Extended Properties='text;HDR=Yes;FMT=Delimited'";

     

    With this connection string i am able to open the connection but when i try to fill the data set it gives me the error:

     

    "Specified Cast is not valid"

     

    the line is

    da.Fill(ds);

     

    where 'da' is the OleDbDataAdapter and 'ds' is the dataset

     

    The complete Block of code is as follows:

    string strConn;     
    OleDbConnection conn ;
    OleDbDataAdapter da;

     

    strConn = "Provider=MS Remote;"+"Remote Server=//ind-spz4dxp612/trial;" + " Remote Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+@"d:/trial/try1.csv"+";"+"Extended
    Properties='text;HDR=Yes;FMT=Delimited'";

     

    conn = new OleDbConnection(strConn);
    da = new OleDbDataAdapter("SELECT * FROM [TRY1.CSV]",conn);

    da.Fill(ds);========== This Is The line which gives this error.

     

    Your help and inputs will be appreciated.
    Thanks.

    Friday, August 17, 2007 5:48 AM

All replies

  • I believe in your connection string you need to specify only the path to the folder where file located and then call select statement with the actual file name as you do right now. Try to remove "/try1.csv" part from the connection string. 

    Friday, August 17, 2007 10:26 AM
    Moderator
  • Thank you so much for your reply.

     

    I did the same as you said but still the error remains the same.

     

    i would also like to bring to your note dat i m using an impersonated user (programatically)

     

    there are two cases:

    one:

    if i include the <identity impersonate="true"> in web config

    and use the following string

     

    strConnA = "Provider=MS Remote;"+"Remote Server="+@"\\<comp name>\<foleder name>;" + " Remote Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+"try1.csv"+";"+"Extended Properties='text;HDR=Yes;FMT=Delimited'";

     

    i get the error "MS remote is  not registered in the local machine"

     

    and if i use the following string

     

    strConnB ="Provider=Microsoft.Jet.Oledb.4.0;"+"Data Source="+"\\<comp name>\<foleder name>;"+"Extended Properties='text;HDR=Yes;FMT=Delimited'";

     

    i get the error " Microsoft.Jet.Oledb.4.0 is  not registered in the local machine"

     

    whereas Microsoft jet with the latesh version is available on my machine (win XP)

     

    and the second is

    if i set <identity impersonate="false"> then with

     

    the strConnA i get the error "specified cast is not valid"

    and with strConnB i get "Unspecified error"

     

    i m really not sure which is the right path dat i should go ahead with there being so many option

     

    it would be really helpful if you could tell me wut would ideally be the right path(i mean whc string should i use and should i set the idedntity to true o not)

     

    i really need this.have been racking my head since quite some time now on this

     

    plz do help

    thanx

     

     

    Friday, August 17, 2007 11:49 AM