Why is my .mdb connection not working?
-
I try to get some data from a .mdb file, but it fails with a realy weird and long exception, here is my code: public DataSet getTranslation(int language) { DataSet translations = new DataSet(); String connes = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Johan\\My Documents\\languageDB1_00.mdb"; String sql = ("SELECT Translation, PhraseKey FROM Translation WHERE languageID = " + language + ";"); OleDbConnection conn = null; conn = new OleDbConnection(connes); //"SELECT Translation, PhraseKey FROM Translation WHERE languageID = " + language + ";"; try { OleDbCommand command = new OleDbCommand(sql, conn); OleDbDataAdapter adapter = new OleDbDataAdapter(command); conn.Open(); adapter.Fill(translations, "Translation"); return translations; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); return null; } finally { conn.Close(); } } The exeption message begins with: IErrorInfo.GetDescription failed with E_FAIL (0x80004005) please help... john
-
I try to get some data from a .mdb file, but it fails with a realy weird and long exception, here is my code: public DataSet getTranslation(int language) { DataSet translations = new DataSet(); String connes = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Johan\\My Documents\\languageDB1_00.mdb"; String sql = ("SELECT Translation, PhraseKey FROM Translation WHERE languageID = " + language + ";"); OleDbConnection conn = null; conn = new OleDbConnection(connes); //"SELECT Translation, PhraseKey FROM Translation WHERE languageID = " + language + ";"; try { OleDbCommand command = new OleDbCommand(sql, conn); OleDbDataAdapter adapter = new OleDbDataAdapter(command); conn.Open(); adapter.Fill(translations, "Translation"); return translations; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); return null; } finally { conn.Close(); } } The exeption message begins with: IErrorInfo.GetDescription failed with E_FAIL (0x80004005) please help... john
Hello John, The problem is because of the usage of the keyword "Translation" as in OLEDB. If you change the SQL to
String sql = "(SELECT [Translation], PhraseKey FROM [Translation] " + "WHERE languageID = " + language + ")";
the snippet will work fine. Regards Mahesh