I'm using this connection string to access excel(2007,2010) files
oleConnection.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties='Excel 12.0;HDR = NO;IMEX = 1;'";
this work fine until i try to get data from protected List.
I know the protection password.
So how could i access protected list?
As per MSDN you can provide the credentials with the connection string User ID=UserX;Password=UserXPassword but this works for access
But
I'm afraid. You cannot open a connection to a password-protected
spreadsheet unless you have already manually opened the spreadsheet in
Excel . The described error is with the
Excel ODBC provider, but the behavior is identical in the Jet 4.0 OLE
DB provider. Your other option is to remove the password from the
spreadsheet, and rely on some other security mechanism (like
restricting permissions on the folder where the file resides) to
control access.
Related
I have asp.net application which loads excel file to read. It works fine on my local development server. However when I upload it to server it wont display the uploaded excel file.
I have MS Office installed on my local machine but not on server.
Thanks for your guidance
The code I am using is...
if (fileExtension == ".xls")
{
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (fileExtension == ".xlsx")
{
connectionString = "Provider=Microsoft.ACE.OLEDB.14.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 14.0;HDR=Yes;IMEX=2\"";
}
//Create OleDB Connection and OleDb Command
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName +"]";
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
con.Close();
GridView1.DataSource = dtExcelRecords;
GridView1.DataBind();
I keep getting error
" The 'Microsoft.ACE.OLEDB.14.0' provider is not registered on the local machine."
Even though I installed Access db and I can see ACE 14.0 still I keep getting this error
Depending on the features of Excel you need you'll need to install Excel on server or the client, or a third party control(s) that understand the format.
If the application is WEB application where the application actually showing the data locally on the client via a web brower : See this MS link : http://support.microsoft.com/kb/162059. Here you're actually sending the xls file/stream to the client.
If you are showing it a WEB application, and shows data on the web page where the rendered content is sent to the client then you need Excel Services on the server (I think this is part of the SharePoint family), or a third party AS.NET control that ready .XLS info and renders it into the page.
If the application is a desktop application that shows excel data in stand alone app where the user logs into the server as a desktop user then you need to have Excel installed on the server. Or you need third party .net control (dependant on app technology WinForms, WFP/Silverlight etc) that can read the .XLS info and present it.
If the application is running on a virtual desktop, say like Citrix, then it's the same as 3.
If all you're doing is reading the files via OLEDB and then working with the data outside of excel then you can install the Access Connectivity Engine for free. This basically the components needed to read various Office data in a need 'service only' package (or driver if you prefer). I don't if allows random access at the cell level, but I know it does allow you to run OLEDB queries over the .XLS file. We use for loading .XLS files into databases.
All of these come with different licensing restrictions and costs. And without any of your use cases, all I can suggest is that you consider that Excel is a chunky set of application components and to use them you need to understand exactly how your application and they will function/interact and also their limitations in any particular deployment scenario you envisage.
Edit:
Further info: If you are running on a 64 server and are using a 32 bit application then the only way I could ACE to work was to install the ACE 2007 and not 2010 version
If you just need to read file content you can use Csv format, wich I think will be the easiest way you can read excel files in your server. you can 'save as' a excel file into *.csv. A csv file is no more than a text file wich is written this way(comma delimited):
"column1","column2","column3"
So now all you just have to do is read a text file.
CVS Files
Hope it helps
You can use OpenXml or ClosedXml - they work on the server
hey,
i am new at connecting to dataBases and for some reason each time i use those following lines my program collapse:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=|DataDirectory|\Company.accdb"
OleDbConnection con = new OleDbConnection(connectionString);
inside my debug folder i got Company.accdb access file
edit:
i am getting 'Microsoft.Ace.OLEDB12.0' provider is not registered on the local machine any idea how to solve it?
thanks in advance for your help
Two things -
This connection string rely on ACE OLEDB provider (typically comes with Office 2007 - your machine need to have this provider)
Connection string is requesting data dictionary. You probably need to use below form:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;
For password protected files, form would be Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;
I will also suggest trying different Provider (ODBC perhaps) instead. For various connection strings for Access 2007, refer http://www.connectionstrings.com/access-2007
The requirements for my application is to browse for an excel file, Upload the file , read each row from the excel file and insert into the database.
I am building this application in Windows Azure.
Prior to this I have successfully used OleDbDataAdapter to read the data from the excel file into the dataset.
The connection strings I used are:
FOR XLS file:
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strNewPath & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"""
FOR XLSX file:
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strNewPath & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""
Will the following providers Microsoft.Jet.OLEDB.4.0 & Microsoft.ACE.OLEDB.12.0 be avaialable in Windows Azure?
Will approach also work in Cloud as well and is this the best way to access Excel files in c#?
Any new ideas and suggestions are welcome.
No, OLE providers will not be available under the Worker Role by default. It might be possible to have them later in a different VM setup though.
For the time being you are basically restricted to .NET-only options:
EPPlus for XLSX
NPOI for XLS
I am using OpenXMl SDK for excel processing. It works perfectly in cloud environment.
Since you mentioned you need to support .xls and .xlsx files, you could use a product like OfficeWriter which supports both file types in one library.
Disclaimer: I am one of the developers on OfficeWriter
I am creating a window application in C# and was thinking of setting up a password on mdb file of MS-Access so that no one can open that file other than my window application or who so ever knows password of that file.
I managed to make that file password protected but unfortunately I was not able to access that file through my application. Actually i not getting where to set the user name and password to open that file. Entering username and password in connection string is not working.
EDIT
Sorry for bit confusion
I want that file to be password protected rather than database connection.
That file should not be opened in any case. For that i managed to set password on file using ms access itself but i m not able to open that file through my application.
Edit2: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb; User Id=""; Password="abc";"
I am using MS-Access 03
Edit 3:
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\Projects\GargTubes\dbGargTubes.mdb;
Database Password=abc;"
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\Projects\GargTubes\dbGargTubes.mdb;JET
OLEDB: Database Password=abc;
Error: Could not find installable ISAM
Try setting the database password in your connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;
You can take a look into that connection strings samples: Connection strings for Access
Since you are talking about passing user name and password, I assume that you have protected your database by setting user rights rather than by using the "database password" option. In that case, users and groups are stored in system.mdw. Be sure to include the path to system.mdw in your connection string (Jet OLEDB:System Database=path\to\system.mdw, see Connection strings for Access for samples).
Alternatively, you use the "database password" feature. Then, the Jet OLEDB:Database Password option described in the other answers should work. To spell it out:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb;Jet OLEDB:Database Password=abc
I'm trying to create an OleDb connection to an Excel file that is located on a SharePoint server. The example code I'm playing with at the moment throws an OleDb exception "Invalid internet address":
public static void ConnectToRemoteExcelFile()
{
string connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes;\";", "http://horde.servername.co.uk/Docs/Documents/Sales.xlsx");
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
}
}
Anyone know how to connect to an excel spread sheet on a web server?
Update
Microsoft support have come back to me and agree that is not possible to connect to Excel files located on a web server. Both Jet .40 and the news ACE (Access Connectivity Engine) do not support this mode of operation. They cite reference to the KB Article "The Import/Link Data on an FTP or HTTP Server Help topic is not correct in Access 2000, Access 2002, Access 2003 and Access 2007"
As far as I know that is not possible, you would have to download the file first, then access it. The reason being is that the file could not be modified given its location.