none
text connection string help RRS feed

  • Question

  • I am using this connection string to connect to a text file

    OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\; Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"");
    
    OleDbCommand com = new OleDbCommand(@"SELECT * FROM MyFile.txt", con);
    
    OleDbDataAdapter da = new OleDbDataAdapter(com);
    
    DataTable tbl = new DataTable();
    
    da.Fill(tbl);
    
    dataGridView1.DataSource = tbl;
    
    the connection works fine , but the problem is that my file has an extention other than txt , it is named : MyFile.dat , when I put it like that , I recieve an error when filling the dataset saying that : Can't Update , file is read only the same file works when I change its extention to txt , in the real world I can't change its extention to txt.

    Any help ????
    Monday, May 4, 2009 7:36 AM

Answers

  • Val is correct. Jet supports a limited number of file extensions. You can either rename the file on-the-fly and then open it or add an entry for the extension to the below Registry key so that the extension is recognized.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\Extensions

    An alternative would be to use the TextFieldParser class.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, May 4, 2009 12:51 PM
  • I got this to work (added dat to end of DisabledExtensions

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text]
    "DisabledExtensions"="!txt,csv,tab,asc,tmp,htm,html,dat"

    http://support.microsoft.com/kb/239105

    dat is disabled for security reasons, so be careful.

    Monday, May 4, 2009 5:36 PM
    Moderator

All replies

  • If I remember correctly (it was long time ago when I had same kind of error), Jet uses extension as type of the file and I had to create a copy of the file in temp folder, rename it to have txt extension and then load data from that file. That might work for you, but would require extra code.
    Val Mazur (MVP) http://www.xporttools.net
    Monday, May 4, 2009 9:55 AM
    Moderator
  • Thanks for your reply , it is a good solution , but I need to access the same file , is that possible ?
    Monday, May 4, 2009 10:29 AM
  • Val is correct. Jet supports a limited number of file extensions. You can either rename the file on-the-fly and then open it or add an entry for the extension to the below Registry key so that the extension is recognized.

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\Extensions

    An alternative would be to use the TextFieldParser class.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, May 4, 2009 12:51 PM
  • If this is just a standard text file why are you querying it? Why not use the StreamReader class?

    If ii is a delimited file you could try to use an Excel object to open it.
    Monday, May 4, 2009 1:36 PM
  • well it is a log file generated by a software and I need to get reports from it by displaying it as a table to the user and let him filter and sort the data.
    Monday, May 4, 2009 1:47 PM
  • I got this to work (added dat to end of DisabledExtensions

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text]
    "DisabledExtensions"="!txt,csv,tab,asc,tmp,htm,html,dat"

    http://support.microsoft.com/kb/239105

    dat is disabled for security reasons, so be careful.

    Monday, May 4, 2009 5:36 PM
    Moderator