0

I have a requirement to upload excel data into a SQL Server 2005 table. Initially I copied Excel data to a temp table and based on condition I have updated and inserted records into the SQL Server table.

Everything works fine in my local system. Same program I moved to quality server there I faced this error

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

Then we installed 'Microsoft.ACE.OLEDB.12.0 provider on quality server. Now this error appearing

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."

Kindly help me out to solve this issue.

SqlConnection con = new SqlConnection();
con = SQLManager.openSQLConnection();

string path = FileUpload1.PostedFile.FileName;
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0 Xml;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [CM_CODE],[CM_NAME],[CM_ADD1],[CM_ADD2],[CM_ADD3],[CM_ADD4],[CM_CITY],[CM_PHONE],[CM_CG_CODE],[CM_CO_CODE],[CM_EXPIRY_DATE],[CM_PINCODE],[CM_EMAIL] from [Sheet1$]", excelConnection);

excelConnection.Open();
OleDbDataReader dReader;

dReader = cmd.ExecuteReader();

Regards, Sathya

4

2 回答 2

2

这很可能是文件权限问题。运行程序的帐户是否具有从文件位置读取文件的文件夹级别权限。

找出程序在哪个帐户下运行,然后将适当的访问权限添加到您上传 Excel 文件的文件夹。

如果是 IIS,那么无论您的应用程序池在哪个帐户下运行,都需要对您上传到的文件夹具有写入权限。权限通常只能由 Web 服务器管理员设置。

翅膀

于 2013-08-27T07:05:23.220 回答
0

最后我找到了解决方案。我在质量服务器的应用程序文件夹下创建了一个文件夹。上传的 excel 表格将存储在这个新文件夹下。以及我在更新我的 SQL 服务器数据库时所指的路径。现在一切正常...感谢大家的支持

问候, 沙迪亚

于 2013-08-28T09:41:25.690 回答