Connection String Error in OleDB

178 views Asked by At

I am trying to Import Excel file through asp.net code. but I am getting ArgumentException when I am trying to create OleDbConnection

An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.

Here is the code

if (FileUpload1.HasFile) 
            {
                string path = string.Concat((Server.MapPath("~/temp/"+FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);
                OleDbConnection oleCon = new OleDbConnection("Povider=Microsoft.Ace.OLEDB.12.0;Data Source="+path+";Extended Properties = Excel 12.0;");
                OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]",oleCon);
                OleDbDataAdapter dtap = new OleDbDataAdapter(cmd);
                oleCon.Open();
                DbDataReader rdr = cmd.ExecuteReader();
                string con_str = @"Data source = .;Initial Catalog=practiceDB;Integrated security=True";
                SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
                bulkInsert.DestinationTableName="Excel";
                bulkInsert.WriteToServer(rdr);
                oleCon.Close();
                Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))),File.Delete);
                Response.Write("<script>alert('Inserted')</script>");
0

There are 0 answers