473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#-Excel: Cannot set PivotCache Recordset with adUseServer

Hello,

I am trying to create pivot tables using data from CSV files. Here is an example:

Expand|Select|Wrap|Line Numbers
  1. String conStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=C:\\";
  2. String query = "SELECT * FROM content0.csv";
  3. Recordset content = new Recordset();
  4. Connection cn = new Connection();
  5. cn.Open(conStr, "", "", 0);
  6. content.Open(query, cn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockOptimistic , 0);
  7.  
  8. Application xlApp = new Application();
  9. Workbook xlWb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
  10. xlApp.Visible = true;
  11. Worksheet xlWs = (Worksheet) xlWb.Sheets.get_Item(1);
  12.  
  13. PivotCaches xlPivCaches = xlApp.ActiveWorkbook.PivotCaches();
  14. PivotCache xlPc = xlPivCaches.Add(XlPivotTableSourceType.xlExternal, Missing.Value);
  15. xlPc.Recordset = content;
  16. PivotTable xlPt = xlPc.CreatePivotTable(xlWs.Cells[1, 1], "test", Missing.Value, Missing.Value);
  17.  
  18. content.Close();
  19. cn.Close();
Running this code gives the following exeption:

Exception from HRESULT: 0x800A03EC
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName, BindingFla
gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.PivotCache.set_Reco rdset(Object )
at Project1.Sandbox.Main() in C:\Documents and Settings\vvishakh\My Documents
\Visual Studio 2005\Projects\Project1\Project1\Sandbox.cs:line 43


The above is caused by the line
Expand|Select|Wrap|Line Numbers
  1. xlPc.Recordset = content;
If I add the line below right before opening the Recordset, the code works and a pivot table shows up:

Expand|Select|Wrap|Line Numbers
  1. cn.CursorLocation = CursorLocationEnum.adUseClient;
However, I want to use asUseServer since some of the files I read in are as large as 100 MB and can contain more than half a million rows. adUseClient uses up all my memory, I get an OutOfMemoryException and the pivot table doesn't load.

I have been grappling with the problem over the past few days and would be very grateful if someone could tell me how to get Excel pivot caches to accept Recordsets using adUseServer.
May 16 '07 #1
1 5059
I've just hit the same problem :)

The only workaround I can think of for the moment is to stay with adUseServer/adOpenForwardOnly and load the data initially into a normal SHEET (allowing up to 1 million rows in XL12, the same limit as an xlExternal pivotcache).

You can then build your PIVOT table on this table data, which works very well with these cursor settings, but initially leads to "double-storing" of the data.

It appears you can then DELETE the data sheet afterwards and SAVE the file, but without refreshing the Pivot. Result looks similar to the xlExternal method and appears to preserve all the pivot table functionaility except REFRESH (which personally I don't plan to use, as we are doing single-use/canned reports).

But I too would appreciate a better solution...

Tony
Jul 16 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Wayne Wengert | last post by:
I have an ASP page in which I reference quite a few ADO constants such as adOpenStatic, adLockReadOnly and they work fine but a reference to adUseServer comes up as undefined? I have a typelib...
4
by: Thomas Scheiderich | last post by:
Why would you use the Recordset object over the Execute method of getting data from your Sql database. For example, I have the following: Execute Method...
2
by: ano1optimist | last post by:
I have a form with a search button. I'm using command parameters to pass search criteria to a stored procedure. Here is my code: Stored procedure: CREATE PROCEDURE . @strCriteria varchar(200)...
1
by: carrionk | last post by:
Hi, I'm currently working with a Legacy System whose only output is pivot tables in Excel. If I need certain data, I change the pivot table to get the information I want. All the info is...
5
by: jonman | last post by:
Hello, I'm a bit of a newbie when it comes to Access (and DB's in general). I've got a form that allows the assembles a SQL string (that I've tested interactively, and proven that it returns...
10
by: shubha.sunkada | last post by:
Hi, I have a recordset connection in asp that I am using to search records.If I use the client side cursorlocation (rs.cursorlocation=3) then it takes really long to return back the records due...
0
by: PCroser | last post by:
I have encountered a problem when querying a table. The query passed data into a recordset which should have resulted in many records but has returned EOF. After debugging the code the only...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
1
by: Mark | last post by:
Hi All, I have been trying to upsize an Access 2003 database to SQL Server. I've had to make a few code changes but I have one module which I can't get to work. The code up until where the error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.