Click here to Skip to main content
15,917,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai

I got an error like this
Quote:
'Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Could not find installable ISAM.".' while transferring database from msaccess to SQL
I have written this code
C#
try
          {
              DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
              DataTable userTables = null;
              using (connection)
              {
                  string mappath = dataGridView1.CurrentRow.Cells["Path"].Value.ToString();
                  string[] filePaths = Directory.GetFiles(@"" + mappath + "", "*.mdb", SearchOption.TopDirectoryOnly);
                  // c:\test\test.mdb
                  foreach (string tr in filePaths)
                  {
                      connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + tr + "";
                      string[] restrictions = new string[4];
                      restrictions[3] = "Table";
                      connection.Open();
                      userTables = connection.GetSchema("Tables", restrictions);
                      List<string> tableNames = new List<string>();
                      for (int i = 0; i < userTables.Rows.Count; i++)
                          tableNames.Add(userTables.Rows[i][2].ToString());
                      try
                      {
                          foreach (string tableName in tableNames)
                          {

                              cn1 = new SqlConnection(con);
                              if (cn1.State != ConnectionState.Open) { cn1.Open(); }
                              SqlCommand cmd = new SqlCommand("select * into [" + tableName + "] from OPENROWSET('Microsoft.Jet.OLEDB.4.0','" + tr + "',[" + tableName + "])");
                              cmd.Connection = cn1;
                              cmd.ExecuteNonQuery();---Got error Here
                          }
                      }
                      catch (Exception Ex) { connection.Close(); }
                      connection.Close();
                  }
              }
          }
          catch (Exception Ex) { }

Would u pls solve this error
Posted
Updated 5-Aug-15 18:29pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900