I am doing this to read :
private bool writetoven(string xlspath)
{
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString)
try
{
OleDbCommand ocmd = new OleDbCommand("select * from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader odr = ocmd.ExecuteReader();
string vcode = "";
string pswd = "";
string vname = "";
while (odr.Read())
{
vcode = valid(odr, 0);
pswd = valid(odr, 1);
vname = valid(odr, 2);
insertdataintosql(vcode,pswd,vname);
}
excelConnection.Close();
return true;
}
catch (DataException)
{
return false;
}
finally
{
lblmsg4.Text = "Data Inserted Sucessfully";
}
}
and my connection string is like this:
excelConnectionString = "provider=Microsoft.jet.oledb.4.0;data source=" +
filepath1 +
";extended properties='Excel 8.0;HDR=YES;'";
but I am getting an error as
The Microsoft Jet database engine cannot open the file ”. It is already opened exclusively by another user, or you need permission to view its data.
Line 1574: OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
Line 1575:
Line 1576: excelConnection.Open();
Line 1577:
Line 1578:
It seems like the file is still open but its not and I have checked the running process and its not there
Now what should I do? …My Excel sheet is closed but I am getting this error
i dont have microsoft access on my com is that can be an issue
is this problem is something to do with my fileupload control that i am using??
Make sure the account your web app is running under has permissions on the file.
Also, since you are not using a path, and just a filename, it might not be finding the file where it is at. Where is the file located relative to your web application?
Does System.IO.File.ReadAllBytes(filepath1) succeeed or fail?
Since you are dealing with a file upload:
The user is uploading from their computer through the browser, and the file is transferred to your server in the post response. See: http://blog.divergencehosting.com/2009/03/12/upload-read-parse-file-aspnet/
Even if you had the full path, you wouldn’t be able to access the file on the user’s computer from your server. The browser sends you a copy of the file in
uploadControl.PostedFile.InputStream;where uploadControl is the name of your asp:FileUpload control.You would then need to save this stream to a file location on the server, and provide this full path to the connection string.
If you used something like EPPlus to read the file instead of the OleDbConnection, you could use the in-memory stream instead of saving the file first.