Tuesday, September 27, 2011

Visual Studio 2008 Deployment project.. Could not create .tmp file.. Access Denied

Project deployment under Visual Studio is quite a simple task, but not this time.
I had a weird error saying ' Could not create c:\prog~1\Local~1\Temp\vs09EBC.tmp'

As usual, tried all possible self determined alternates but nothing worked and after googling for nearly an hour.. the reason found to be my Kaspersky Internet Security !!! Strange..

Its was the Antivirus, Kaspersky Internet Security which was behind this error generation., the solution...
Just pause the realtime protection for few min .., say 3 min. and compile... Bingo..

Thanks for the original poster.. but thought to share it as some may solve it easily...

Keep programming, keep blogging :)

Thursday, August 25, 2011

Reading Excel from .NET

Often we need to implement reading an Excel workbook via .net applications and because of the ADO.NET advantages, it seems quite an easy task.

Just create a connection string, create a data reader or a Data table and read your excel sheet .!!

Your connection should be something similar to

cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & yourfilename & ";Extended Properties=""Excel 8.0;"

But, the main problem is when your Excel sheet contains columns, which are mixed, i.e. your columns values have Numbers and Text both.

In this situation, just by adding IMEX=1 in your connection string , should make life easier.

cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strServerFileName & ";Extended Properties=""Excel 8.0;IMEX=1"""

Please note that the Extended Properties value is enclosed in quotes.

What happens by using IMEX=1 is, this option tells the connection to honor the registry value ImportMixedTypes = Text, located at HKLM\Software\Microsoft\Jet\4.0\Engines\Excel\

Again if, in some situations, you are supposed to read number from a column and the first few values in the column, say about 10-15 cells are empty, then we face the evil. :)

This is because, when deciding the data type of each and every column, the system will check for the registry key HKLM\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows

If the the TypeGuessRows value is, say, 8, and the column's First 10 values are Null, then the column all the values from that column is treated as Null, when everything seems perfect !!!.

So, if you are not getting the values from Excel, first and foremost thing to check and change is the HKLM\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows value.

Change the TypeGuessRows value as per your requirement and TypeGuessRows value = 0 means all 64465 cells to be scanned before deciding the DataType of the Column.

Hope this helps someone at sometime.. :)

Cheers , Happy coding...

Hemanth Kelkar