Tuesday, July 14, 2015

SharePoint Excel File Upload : System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)

Hello,

When your writing SharePoint Custom solutions for file upload or importing excel file data into SharePoint list.If you get the below error.

"System.Data.OleDb.OleDbException: Unspecified error
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()"

Solution:

Go to Web.Config file of your SharePoint Web Application application.The location of web.Config File is looks like this .C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config. My Web application port number is 80 so I am navigating to above Folder. Check you Web Application port number and navigate to Web.Config file folder.

Then Open Web.Config File and Find The below Tags as shown below.By default Impersonate will be set to true so you neeed to change it to false as shown in below screen shot:


More about Impersonation:

Impersonation, a feature that was added in Windows SharePoint Services 3.0, enables you to perform actions on behalf of another user. Impersonation is useful in scenarios such as timer operations that need to update something asynchronously on behalf of a user long after the user has stopped using the Web site (that is, when their workflow is completed).

Thanks for Reading!
Hope Your Issue Resolved!

Regards,
Kiny :)
  




Friday, July 10, 2015

SharePoint File Upload : The Microsoft 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.

Hello,

I have faced same Issue when uploading excel file into SharePoint list:

Problem: 

Before resolving this issue,I was directly browsing the excel file from local system.When i click on upload button, I keep on getting Error "The Microsoft 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 "

I was reading excel file using file upload control as shown below:

         if (!uploadfile.HasFile)
            {
                ltrlMsg.Text = "Please select a valid Excel File";
                return;
            }
            try
            {

                 //reading file from file upload control.

                 string fileName = uploadfile.PostedFile.FileName;

                //Some code goes here
            }
             catch (Exception Ex1)
               {
                            ltrlMsg.Text = Ex1.Message;

                 }

For Reference:


Solution: 

Then am storing excel file in root directory then reading file path from root directory using file upload control as as shown below:

Create New Folder in Root directory of SharePoint Web application as shown in below screen shot.
Example: I have created a folder named "GnIExcelFiles" in root path.

Root Path: C:\inetpub\wwwroot\wss\VirtualDirectories\41417

Here 41417 is port no of my Share Point web application in , check which is the port number of your web application and create new folder as described.


Then Change the code  as shown below:


string uploadexcelfile = Path.GetFileName(uploadfile.PostedFile.FileName); uploadfile.PostedFile.SaveAs(Server.MapPath("~/GnIExcelFiles/") + uploadexcelfile);
string fileName = Server.MapPath("~/GnIExcelFiles/") + uploadexcelfile;

For Reference:



I resolved my issue using above small piece of Code :)
Give A try , It will work

Thanks for Reading !

Kiny!