2

We've been programming with a connection that "simulates" a CSV into a database.
We used it with all our applications, but now we needed to do the programming on Visual C# Express 2008 while we previously used Visual Studio 2012.
We changed our Framework from 4.5 to 3.5 because that is what Express 2008 can use.
Then we removed some "unneeded" using Systems. Now we removed the try and catch to see what the problem was which is: "Provider cannot be found. It may not be properly installed."
This is the code what was wrong:

string fileNeem = Path.GetFileName(strFileName4);
string sepperator3 = Convert.ToString(textBox2.Text);
string root = Path.GetDirectoryName(strFileName4);
if (File.Exists(@"" + root + "/schema.ini")) { File.Delete(@"" + root + "/schema.ini"); }
string[] lines = { "[" + fileNeem + "]", "Format=Delimited(" + sepperator3 + ")", "DecimalSymbol=(,)" };
System.IO.File.WriteAllLines(@"" + root + "/schema.ini", lines);

ADODB.Connection oConn = new ADODB.Connection();
oConn.Open("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName4) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\";", "", "", 0);
string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName4) + "]";
ADODB.Recordset rs3 = new ADODB.Recordset();
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter();
rs3.Open(strQuery, "Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName4) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\";",
ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 0);
adapter.Fill(dtAttrSet, rs3);
dtAttrSet.Columns.Add("");
if (File.Exists(@"" + root + "/schema.ini")) { File.Delete(@"" + root + "/schema.ini"); }
rs3.Close();
oConn.Close();
gvAttributeSet.DataSource = dtAttrSet;
return dtAttrSet;

Also, we use a schema.ini file to store the delimiter. This file is removed soon after the datatable is filled.
I have seen a lot of questions and answers but it seems that it is ASP or they used Excel.
Is there anything we did wrong?

Masoud Mohammadi
  • 1,523
  • 1
  • 20
  • 39
Sj03rs
  • 919
  • 10
  • 30
  • Had you used same connection string for csv files in vs2012 code too? – SV. Jan 07 '15 at 08:22
  • 1
    Jet.OleDb.4.0 requires x86 as Target CPU. Check you Configuration Manager – Steve Jan 07 '15 at 08:24
  • @Steve We used Visual Studio 2012 on a 64 bit system with windows 8 And we transferred it to a 64 bit system with windows 7 – Sj03rs Jan 07 '15 at 09:05
  • 1
    Yes but if your app is compiled for AnyCPU or x64 it cannot find the JET.OleDB.4.0 when it runs on x64 SO also if it is installed on that machine. You need to have your app compiled for x86. See this QA for the reverse side of the coin http://stackoverflow.com/questions/17716207/the-microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine-w/17716238#17716238 MS-Access doesn't requires complex installations of server and services but is nevertheless a deployment nightmare. – Steve Jan 07 '15 at 09:25
  • @Steve Alright, thanks! I'll take a look at it! – Sj03rs Jan 07 '15 at 09:48
  • @Steve Yes! Thank you very much! I changed it to x86 and it worked! I've upvoted your answer. – Sj03rs Jan 07 '15 at 13:38

1 Answers1

1

Steve is right : Provider=Microsoft.Jet.OleDb.4.0 only works when compiling platform x86 target. As far as i know there is no way around this and no plans to add support.

However it might be possible to use ACE 64 Provider=Microsoft.ACE.OLEDB.12.0 (link)

Margus
  • 18,332
  • 12
  • 51
  • 101
  • 1
    Yes, I've done the things he suggested and it worked! Also, thanks for your answer, I will mark it as answer! – Sj03rs Jan 07 '15 at 13:39