Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
chkProc = 0;
OleDbConnection oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("" + pathss + "") + ";Extended Properties=Excel 12.0;Persist Security Info=False");
OleDbCommand ocmd = new OleDbCommand("select * from [" + sheetss + "$]", oconn);
oconn.Open();
OleDbDataReader odr = ocmd.ExecuteReader();


this error occurs when transferring huge data from excel to sql server 2005 it occurs at the time of oconn open();

plz hlp me...
Posted
Updated 14-Nov-13 1:55am
v2
Comments
Then select certain number of rows at a time and try.

1 solution

Hi,

Use this below code and read the data from EXCEL and convert to Dataset and then do the process of inserting data from the Dataset to the SQL Server DataBase.

using System.Data.OleDb;
using System.IO;
using System.Data;


  private DataSet GenerateExcelData()
        {
            DataSet ds = new DataSet();
            try
            {
                string path = System.IO.Path.GetFullPath(Server.MapPath("Excel/InformationNew.xlsx"));
                if (Path.GetExtension(path) == ".xls")
                {
                    oledbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"");
                }
                else if (Path.GetExtension(path) == ".xlsx")
                {
                    oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
                }
                oledbConn.Open();
                OleDbCommand cmd = new OleDbCommand(); ;
                OleDbDataAdapter oleda = new OleDbDataAdapter();
                cmd.Connection = oledbConn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT * FROM [Sheet1$]";
                oleda = new OleDbDataAdapter(cmd);
                oleda.Fill(ds, "excelData");
                return ds;
            }
            catch (Exception ex)
            {
                return ds;
            }
            finally
            {
                oledbConn.Close();
                oledbConn.Dispose();
            }
        }
 
Share this answer
 

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