Category Archives: Microsoft Visual Studio .Net

Debugging JavaScript in asp.net User Controls

Little while back I was facing issue is debugging JavaScript code written inside an asp.net User Control (ascx) file in visual studio 2010.

Interesting thing is that breakpoints doesn’t work for User Controls in asp.net but you could still do the debugging if you write debugger; keyword before the line where you want to set the breakpoint. The visual studio will automatically detect this keyword in your code and would pause the execution at that line in debug mode.

But in my case even the debugger keyword was not working. Whenever visual studio designer used to encounter this keyword, VS used to halt at the first line of page’s markup (pagename.asps[dynamic]), and by this I could not find that exactly which of my debugger statement got hit.

The issue seems to be of the page’s temporary file/markup generated by VS.

Solution

deleted the website’s .pdb file from project’s bin folder and things started working.

Hope this information would help someone other there in coding world.

Thanks


Entity Framework Function Import not returning Columns data

While working with Entity Framework (EF), sometimes the EF doesn’t recognize the columns returned by the Stored Procedure.


Reason

1) If the db procedure is using temporary table (e.g. #tempTable), EF don’t recognize the MetaData from the procedure.

2) If multiple select … statements exists in db procedure.


Solutions

Before executing procedure or beginning of db procedure set the FMTONLY to ON like below line:

SET FMTONLY ON

This will force EF to read the metadata from Temp tables


Disadvantage

There would be performance issues with approach because the way EF read the metadata from temp tables is to execute them multiple times.


Workaround

Instead of using the temp tables, create table variables and use them to store data temporarily. While using this option you don’t need to set the FMTONLY setting.


Performance

Using the table variables will be faster than FMTONLY option.


Find more detailed information at 

http://munishbansal.wordpress.com/2009/02/18/set-fmtonly-on-useful-in-tsql-ssis-packages-for-using-temp-tables/


Thanks


Parameter is not valid. Asp.net GDI exception

I was getting this exception while working with the GDI images in asp.net.
My requirement was to upload the image from client then resize it and display.

The code was working fine on local development machine, but on production server it was throwing “Parameter is not valid” exception.

The general cause of this is that non-availability of resources required to generate a valid image file.

In my case the reason was that the destination folder was having read-only permissions, which was causing the code to hault while saving the processed image back to server.

For the resources I read during this issue, I found out some more reasons, these can be following:
1) Invalid source image path passed to the Drawing/Image/Bitmap object.
2) Invalid destination image path passed to the Drawing/Image/Bitmap object.
3) Corrupted/incomplete byte array.
4) Disposing of Source object before completing generation of new Image.
5) Folder write permissions while saving the new file.


Read & Write to System Registry data, keys using C#

In this post i am going to explain that how to access the System Registry and how to read and write data to registry.

Step 1: First you need to import the below namespaces:
using Microsoft.Win32;

Step 2: Now create an object of Registry class:
RegistryKey regkey;

Step 3: Now access the registry and get the value of a key

regkey = Registry.CurrentUser.CreateSubKey(@”Software\Microsoft\FTP”);

if (regkey.GetValue(“Use PASV”) == null)
{
txtValue.Text = “No Value Specified”;
}

else
{
txtValue.Text = regkey.GetValue(“Use PASV”).ToString();
}

The above code gets the value of the “Use PASV” key from the
Registry\CurrentUser\Software\Microsoft\FTP path.

Step 4: Set the key value
regkey.SetValue(“Use PASV”, txtValue.Text);