Excel + ADO.NET + Closing Files?

Hello everybody, I am attempting to manipulate excel workbooks using ADO, and this has been working perfectly for some time on my development machine.

I have started to run into problems with what appears to be the file handlers not being closed correctly (cant access file after completion etc). What is the best way of pinpointing this?

At the end of any code path which has the file open for writing using ADO i close the file handler as such:

objConn.Execute(strSQL)
objConn.close()
objConn = Nothing

 
Is there any way (other than this code not being reached) that could result in the file being still open?

 

0
AndyJones
10/24/2006 3:41:42 PM
asp.net.free-for-all 9281 articles. 0 followers. Follow

1 Replies
517 Views

Similar Articles

[PageSpeed] 17

Because is an excel file you need to make sure there is no error when accessing. If you get an exception you'll never call close and your excel file will stay open. Do this:

try

{

 Open Connection

objConn.Execute(strSQL)

}

catch

{

 // Error

}

finally

{

obj.Close();

obj.Dispose(); // don;t need that

}

 


Cheers
Al
My Blog
MapStats.NET
Please click on 'Mark as Answer' if this post answered your question!
0
albertpascual
10/26/2006 1:33:40 AM
Reply:

Similar Artilces:

ADO.Net for Excel files
I wrote a windows form application in C# that uses ADO.Net to read from an Excel file. I receive xls files but have to manually save them as xlsx files because I can't get the program to read xls files (I get "External table is not in the expected format"). As an aside, for broadest .net compatibility, I set each of the Projects (which create assemblies/dlls) for the application to .net framework 2.0. I have 2 questions: 1. How can I get my program to read xls files when Excel 2007 is installed? 2. How can I support environments where Excel 2002 and Excel 2003 are installe...

Does .NET map calls for ADO to ADO.NET?
Hello,We are trying to troubleshoot some DB problems from COM objects that call ADO. I heard that when ADO is loaded inside of a COM object by a .NET app, that .NET intercepts the call and re-maps those calls over to ADO.NET. This seems untrue to me, given the nature of ADO.NET being a totally separate technology.Does anyone know for sure whether this does or does not occur?The problem we are seeing is actually almost identical in symptoms to this:http://support.microsoft.com/default.aspx/kb/230101"FIX: Data Queries Sporadically Return Empty Recordsets" Literally, this is what...

Close Excel file using VB.NET
Hi all, I need an urgent help here. I have a excel file which protected by a password, and the excel file itself already have closing code in ThisWorkbook. I need to use VB.NET to read this file, I read successfully open this file using the Workbooks.Open function and pass in the password. But whenever I want to close this excel file, it will run a dialog box. Is there any possible way to tell the dialog box "yes" or "no" using coding in .NET? I will put the closing code and my .NET code here. ================================================...

ADO in VB6 vs ADO.NET in VB.NET
I am writing a database interface and I would like to know whether a VB6 interface using ADO or a VB.NET interface using ADO.NET would be faster in terms of just performing database operations. Is there an explanation for this, and what is the magnitude of the difference? Thanks in advance!...

ado.net or/and datawindow.net
Hi, Can datawindow.net work with Sybase's ado.net or are they not compatible with each other. We have two separate groups of developers, one group develops web apps using ASE as the back end for the data, so they use a combination of Visual Studio ..NET and Sybase's ado.net to do their work. We have another group that develops client/server apps using Powerbuilder, but since 80% of their work is in writting reports using Powerbuilder, I was wondering if they could use a combination of datawindow.net and ado.net to put make these reports available on the web through ...

Where is the ADO.NET Sybase driver for .NET 1.1 and .Net 2.0?
Hi All Does anyone know where I can get the Sybase drivers for ADO.NET for both versions, 1.1 and 2.0/3.0? Cheers Chris Burrell Hi Chris, There is no release of ASE ADO.NET Provider 2.0 (I assume you refer to ASE provider, not ASA - if ASA please port to sybase.public.sqlanywhere.general). For the 1.1 Provider: It is available in the ASE SDK for windows or the PC Client CDRom included with ASE product. On the SDK its available as 12.5.1 and 15.0 On ASE PC Client I think 12.5.1 is part of ASE 12.5.X and 15.0 is part of ASE 15.X 2.0 provider should release som...

Problem when get data from Excel file using ADO.NET
THIS IS MY CODE Private Sub GetDataFromXLS() Dim strConn As String Dim objConn As OleDbConnection Dim sql As String strConn = _ "Provider=Microsoft.Jet.OLEDB.4.0; " & _ "Data Source=C:\Data.xls;" & _ "Extended Properties=Excel 8.0;HDR=Yes;" objConn = New OleDbConnection(strConn) objConn.Open() sql = "SELECT ProductCode, ProductName FROM [Data$]" '-Data is name of sheet in Data.xls. Dim objComm...

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

SpreadsheetGear for .NET Release Candidate, a royalty free Microsoft Excel spreadsheet component for the Microsoft .NET Framework, is available for download.
9/12/2005 - SpreadsheetGear for .NET is a royalty free Microsoft Excel compatible spreadsheet component built by industry veterans for the Microsoft .NET Framework. SpreadsheetGear for .NET provides .NET Framework developers the tool they need to leverage the existing skills of Excel users by allowing these users to design reports, specify business rules, set up complex calculations and provide tables of data in a form in which they are both knowledgeable and comfortable. SpreadsheetGear for .NET features the fastest spreadsheet calculation engine available. All of Excel's financial, date, ...

Open a excel file show it for 10 sec and then close it by using vb.net
Hello FrinedsI in a problem...The client required to open a number of excel files from a folder, show it for twenty secounds and then close it.It should happen it the cyclic manner.The page should also scroll... You can say i want to make a slide show of the excel sheet...Any kind of help would be great ThanksAmit ...

ADO.NET Visual Studio 2005 Install Help!, ADO.NET Missing
 Hi everyoneI have a real annoying problem, I have installed Visual Studio 2005 with C#,C++,Web Applications.. Before I installed VS2005 I made sure I had all the .Net Download from 1.1 to 3.5 with the Service Packs, I also Installed a VS2005 Patch that was around 430mb. I have tried this on 3 computers, two of XP and 1 vista.I need ADO.NET Functionality, When I choose to create a Web Application in C#, I require the ADO.NET Entity Data Model as it will allow for a graphical interaction with a SQL db. However When I Choose Add New Item in Solution explorer there is no ENtity Mode...

ado.net and .net 2.0
Does anyone know if there has been any notable changes to ADO.NET in .NET 2.0 in the areas of data access (both reads and writes) except for the new SqlDataSource and equivalent user controls? Try these links for  tutorials. Hope this helps.http://beta.asp.net/QUICKSTART/aspnet/doc/data/advanced.aspx#nulls http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/mandataaccess.aspKind regards,Gift Peddie...

ADO.NET and Excel
 I am using ado.net and excel for a web app.  I have to write to the excel file which thus far has been easy.  One issue I have is when creating a workbook with the following line makes all fields have a single apostrophe in the cell when I do an insert.   I think the problem is that I use char as the data type but there is no other choice and I have to specify one it seems like from the error message I get from excel. "CREATE TABLE InventoryData (Attributes char(255), AttributeValue char(255))" I have tried a ton of ideas so just shoot and i will let you know if ...

Excel/ADO.net
I wrote the following code (code below) which opens an excel spreadsheet named Book1.xls. Afterwards it writes the text 5 in cell A7 and the text "Cell G3" in cell B7. This works okey the only issue is that when I open the spreadsheet and place the curser in cell A7 the number 5 is formatted as text instead of a number. (warning message: The number in this cell is formatted as text or proceeded by an apostrophe) Any ideas how to make it so its formatted as a number instead of text?ThanksOleDbConnection conOleDBConnection = new OleDbConnection();      &...

Web resources about - Excel + ADO.NET + Closing Files? - asp.net.free-for-all

2006 Commonwealth Games closing ceremony - Wikipedia, the free encyclopedia
... guitar (equipped with pyrotechnics which produced sparks) whilst being lowered onto the stadium ground, giving a rock concert feel to the closing ...

Facebook Is Not Closing For Maintenance Feb. 29 To 31: Care To Guess Why?
Facebook users, repeat after us: “30 days hath September, April, June, and November. All the rest have 31, excepting February alone, and that ...

We Are All 'Closing Time': Why Semisonic's 1998 Hit Still Resonates
At some point, it was decided that in order for a song to be great, it has to “stand the test of time.” This has since become a ...

Deadline for Closing of Facebook’s WhatsApp Acquisition Pushed Back by One Year
... to certain adjustments such that the cash paid will comprise at least 25 percent of the aggregate transaction consideration. After closing, ...

CNBC's Closing Bell (@CNBCClosingBell) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Closing time: The 7 Immutable Laws of Sales Negotiation
A group for sales and strategic account negotiation experts stop the carousel Announcement from Closing time: The 7 Immutable Laws of Sales Negotiation ...

Blockbuster store closing sale - Flickr - Photo Sharing!
Explore The Consumerist's photos on Flickr. The Consumerist has uploaded 2057 photos to Flickr.

Amazing 9 year old Asean Johnson brings the crowd to their feet at Chicago school closings rally - YouTube ...
By the end of this speech hundreds vowed to vote for Asean for Mayor in 2025, maybe even President. Asean (ah-Shawn) goes to Marcus Garvey Elementary ...

Queensland drought: Country pubs closing doors as businesses fold - The Courier-Mail Search Search
QUEENSLAND’S crushing drought has bought small business to its knees across western towns as farmers cease buying locally, or socialising at ...

PSA: Rdio closing on 22 December, download your playlists now or lose them forever
... Streaming Music For more news on Apps , Music , and Streaming Music continue reading at 9to5Mac . What do you think? Discuss "PSA: Rdio closing ...

Resources last updated: 12/29/2015 9:45:57 PM