I am using a FileUpload control to allow the user to import the contents of an Excel spreadsheet into an DataAdapter and then import into an Oracle database table. This works great when I use a local filesystem project. However, when I try to run this on the server, I get an error that the file is opened exclusively or doesn't have permissions. I am assuming it is some type of permissions error. What type of permissions do I need?

Here is the code I used

public static void uploadReleaseDates(string fileName)
    {
        string strConn;

        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=" + fileName + ";" +
            "Extended Properties=Excel 8.0;";


        DataTable dt = null;       
        string str = String.Empty;

        using (OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn))
        {
            using (DataSet myDataSet = new DataSet())
            {
                try
                {
                    myCommand.Fill(myDataSet, "ExcelInfo");

                    strSQL = " INSERT INTO labstat.news_release_archives " +
                                " (abbr,  reference_period, release_date, upload_date, upload_by ) " +
                                " VALUES " +
                                " (:abbr, :reference_period, :release_date,sysdate, :upload_by) ";

                    using(objConn =  new OracleConnection(getConnection()))
                    {
                        objConn.Open();
                        using (objCmd = new OracleCommand(strSQL, objConn))
                        {
                            using (dt = myDataSet.Tables["ExcelInfo"])
                            {
                                
                                foreach (DataRow dr in dt.Rows)
                                {
                                    if (dr[0].ToString().Length > 0)
                                    {
                                        objCmd.Parameters.Add("abbr", OracleDbType.Varchar2, ParameterDirection.Input).Value = dr[0];
                                        objCmd.Parameters.Add("reference_period", OracleDbType.Varchar2, ParameterDirection.Input).Value = dr[3];
                                        objCmd.Parameters.Add("release_date", OracleDbType.Date, 
                                            ParameterDirection.Input).Value = (DateTime)dr[2];
                                        objCmd.Parameters.Add("upload_by", OracleDbType.Decimal,ParameterDirection.Input).Value = 
                                            Decimal.Parse(HttpContext.Current.Request.Cookies["userID"].Value.ToString());
                                        objCmd.ExecuteNonQuery();
                                        objCmd.Parameters.Clear();
                                    }
                                    else
                                    {
                                        return;
                                    }                                    
                                }

                            } 
                        }

The exact error I get is this:

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.

Please close the ms-access database file/tool while running this page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.