WebアプリケーションのためにデータをExcelに読み込んでデータベースに格納しようとしていますが、オープン中にOleDbConnectionにエラーが発生します。OleDbConnectionを開いているときにハンドルされない例外が発生しました
それはエラーを示しています
The Microsoft Office Access database engine cannot open or write to the file. It is already opened exclusively by another user, or you need permission to view and write its data.
事前にsolution.Thanksを持っているなら、私に知らせてください。
string path = FileUpload1.PostedFile.FileName;
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=" + path + ";Extended Properties=Excel 12.0;";
OleDbConnection olcon=new OleDbConnection(excelConnectionString);
try
{
olcon.Open();
}
catch (NullReferenceException) { }
OleDbCommand cmd=new OleDbCommand("SELECT * FROM [Sheet1$]",olcon);
OleDbDataReader dr;
dr=cmd.ExecuteReader();
SqlBulkCopy bulkcopy=new SqlBulkCopy("Data Source=.\\sqlexpress;Initial
Catalog=MvcDB;Integrated Security=True");
bulkcopy.DestinationTableName="EMPLOYEE";
bulkcopy.WriteToServer(dr);
olcon.Close();
oledb接続 – Krishna