Feb 2, 2011

Copy XmlNode from one XmlDocument to another

This one is more for the archive, but it is not widelly used so you may not know it.

In case you need to copy XmlNode from one XmlDocument to another, you need to do two things.

1. Import the XmlNode from the source XmlDocument to the target XmlDocument, using Import(XmlNode node, bool deep) method of the target node,
2. Get the result from this method (it is XmlNode) and use AppendChild method of the node that should be parent of the node to be transfered.

In other words:
XmlDocument sourceDocument = new XmlDocument();
XmlDocument targetDocument = new XmlDocument();

sourceDocument.LoadXml("");
targetDocument.LoadXml("");

XmlNode nodeToImport = sourceDocument.SelectSingleNode("//nodes/sourceNode");
XmlNode importedNode = targetDocument.ImportNode(nodeToImport, true);
XmlNode parentTargetNode = targetDocument.SelectSingleNode("/nodes/targetParentNode");
parentTargetNode.AppendChild(importedNode);

is enough to import the sourceNode with all its child nodes under the targetParentNode of the target document.

Jan 21, 2011

Limit Microsoft SQL server memory usage

I had to work with a fairly large database on my PC.
It became very unresponsive so I checked what's going on.
I clicked on the Performance tab in Windows Task Manager and noticed that the RAM was more then 7 GB (too much for a personal computer, don't you think?).

I realized that 4 of those 7 GBs were used by the MSSQL server.
I went to management studio, right clicked the server and choosed options.

Then I clicked on the Memory page and saw that MSSQL Server was allowed to take up to 2048 TB of memory (couldn't even imagine that):

I limited the server to 1 GB and my PC was healthy again (the queries I do may take a bit longer but at least my ALT + TAB key combination is working again :).

Limit MS SQL Server memory usage.


Simple thing that improved my experience a lot.

Nov 5, 2010

The status code returned from the server was: 12031

If you checked anything on your mind about this code, it may be because of StackOverflow exception rised within your code / or in .NET which is less possible.


Just to let you know as it happened to me ;).

Oct 23, 2010

Rad Ajax controls Q3 2010 is now live!

Just a quick post to let you know that you can download and play with the Q3 2010 version of Telerik's Asp.Net AJAX controls.

What's new:
1. RadTreeList, a control that is hybrid, combining treeview and a list view.
2. RadButton - inherits the functionality of LinkButton, Button and ImageButton and ads more such as the abillity to combine text and image, toggle modes and more. Combined with rich client side API.
3. RadCalendar now has long anticipated feature - the range selection will allow you to select date ranges.
4. Multi month view with postback enabled.


And many more.
Visit Stefan Rahnev's blogpost or the Telerik Labs for more details on the beta.

Oct 12, 2010

Internet Explorer 8 difference between CTRL + R / CTRL + F5 / F5 and enter in the address bar.

I see there is some difference.
We are currently having issue under IE in our site and we noticed that using any of the combinations will casue the Facebook Button to disappear.
If you click in the address bar and then click enter you will see the facebook buttons appear.

Very strange behavior.

Sep 14, 2010

A program in Fortran :)

I am blogging from my university :).
In case you need to write a program in Fortran to calculate the length of a line between tow points, there it is:

program otsechka
implicit none

integer::p1x, p1y, p2x, p2y
real:: resultX, resultY
real::finalResult

write(*,*)'P1 x : '
read(*,*)p1x
write(*,*)'P1 y : '
read(*,*)p1y
write(*,*)'P2 x : '
read(*,*)p2x
write(*,*)'P2 x : '
read(*,*)p2y
resultX = p2x - p1x
resultY = p2y - p1y
! ** 2 is to the power of 2.
finalResult = Sqrt((resultX ** 2) + (resultY ** 2))
write(*,*)finalResult
end

Nice, huh ;).

Sep 9, 2010

It's time to vote again!


It is again time to vote for your best tools in the software development.
Don't waste time, showing some love to one vendor or another will help that vendor push harder in the right direction.

So click on the image and show some love to your favorite vendor.

Aug 9, 2010

Being more productive with command aliases in Visual Studio 2010

We all know we are trying to cut the mouse usage to the lowest possible rate (are we getting back to DOS)?

I think it is easier to hit few keystrokes instead navigating through 4-5 levels of menus.

So here is a nice article on the Commands window usage in Visual Studio that may help you run faster through this:

Understanding Commands: Aliases

Jul 19, 2010

Site is recycled + ThreadPool.QueueUserWorkItem


Just to let you know that you may experience this issue.

If you have an unhandled exception it may be because of a job queued using ThreadPool.QueueUserWorkItem method.

Actually it appears that although the exception is not affecting the main thread (it was in another one) - the .NET will kill the running process (w3wp in our case).

As far as I read this behavior is implemented since .NET Framework 2.0.
It is because you may miss unhandled exceptions in a child thread (if it's in the main thread the process will be terminated in a windows application).

I imagine each request to a web server as a separate thread so I am kind of worried why unhandled exceptions aren't killing the W3WP process as well.
It only seems to be killed if you create another thread in the request thread and this another child thread exits with unhandled exception.

Will need to investigate a bit more about that.

Jul 14, 2010

Q2 2010 is comming!


Telerik RadControls for Asp.Net Ajax and



Telerik Extensions for ASP.NET MVC are released.


See this post for more information on the cool new things included!


Enjoy!

Thread was being aborted. Exception on Response.Redirect()

This is actually an old issue but I try to make sure I have most of the things that stopped me at some point so I can easilly search.

So if you experience the "Thread was being aborted." exception on Response.Redirect(string Url), it is because this method internally calls Response.End().

In order to prevent it to do so, you will need to use the overloaded version that requires another boolean parameter (something like "bool endResponse", don't remember it exactly).

So the thing that should solve it is:

Response.Redirect("http://donchevp.blogspot.com", false);
This way you should avoid "Thread was being aborted.".

Hope I helped a bit ...

Jul 8, 2010

Go download Telerik Ultimate collection trial!

We have the Ultimate collection uploaded @ telerik.com.
You can reach it by using the green "Download"button at the top of the page.



Included in the bundle you will find:

1. RadControls for ASP.NET AJAX
2. Extensions for ASP.NET MVC
3. RadControls for Silverlight
4. RadControls for WPF
5. RadControls for WinForms
6. Telerik Reporting
7. Telerik OpenAccess ORM
8. JustCode
9. JustMock
10. WebUI Test Studio Dev Edition

Direct link to the page: http://www.telerik.com/download.aspx

Hope you like the new download page.

Jun 18, 2010

How does your manager make a coffee?


I had an architectural problem yesterday.
I was working on a methods and managers I won't disclose but will analogy instead.



Imagine you have a coffee manager. Let's name it CoffeeManager.
In my case not only I had coffee manager but also I had a SugarManager, a CupManager etc.

In order to take a coffee without sugar in a plastic cup I should do something like:

Sugar sugarObject = SugarManager.GetSugar(Sugar.None);
Cup plasticCup = CupManager.GetCup(Cups.PlasticCup);
Coffee shortCoffee = CoffeeManager.GetCoffee(sugarObject, plasticCup);

And this happens at the very frontend of the project (in ascx for example).
And not only it happens that way but the managers are spread in few different projects.

So in the frontend I need to call few different managers, get some results from them and pass those results to the manager that should be doing my job.

I also need to handle all the problems that may rise in the managers so I get a lot of code in the frontend just to get something that in my opinion for that particular case should be returned calling a single method and auto handled in the manager.

I think the front end shouldn't care about business operations that much, also as I said the managers were in different assemblies so I ended up adding few references to the frontend project.

I refactored the code so the CoffeeManager can do this job internally (drawback is that the matrix of all combinations of sugar and cup should be added as a methods in the CofeeManager, but I can live with that).

Jun 7, 2010

Open Access Exception : Please reformulate the query so that the parameter appears on the right side.

You may come up with this exception : Please reformulate the query so that the parameter appears on the right side. in Telerik Open Access

If you have something like:

query = query.Where(x => x.Positive == (positive ? 1 : -1));

The bolded text is an iif expression that the Open Access Linq driver cannot evaluate.

The solution is to use something like:

int iPositive = positive ? 1 : -1
This way the SQL will have the evaluated expression and will know how to deal with it.

NOTE: As far as I know this issue is fixed in the latest releases of Open Access ORM.

Jun 2, 2010

Telerik Open Access exception : The assembly 'xxx' does not have a config file with an openaccess node.

In some old versions of Telerik Open Access you may come to this exception.
I am not quite sure about the latest versions.
However, I've found a forum post that explains that this exception occurs if your project wasn't yet enabled for Open Access.
This wasn't my case so I tried some other things.
At the end, it appeared that "The assembly 'xxx' does not have a config file with an openaccess node" exception may occur if your app.config file is broken. It should be a valid XML file. In my case I have forgotten to close a <class> node with its corresponding </class> ...

Edit: As Yosif Yosifov stated, there is an easier way to check if your app.config file is fine. Simply select Telerik -> Open Access -> Configuration -> Check Settings ... dialog from Visual Studio menu.

May 27, 2010

US courts website runs on sitefinity

Just to inform you that the U.S. courts website was launched by DeepBlue. The site is using our CMS - Sitefinity.

Some more information about the project may be available soon.

Here is the site:

http://www.uscourts.gov/Home.aspx

Hopefully we will see some more .gov sites to be using our precious CMS.

May 20, 2010

Cool MCP business card builder site

I've build a simple business card for me at :
https://www.mcpvirtualbusinesscard.com/VBCServer/b087303c-09bf-4832-9269-83483d5c2d35/profile

You can do this also. It takes 2-3 minutes.

Apr 28, 2010

Nice productivity feature in Visual Studio 2010

I really like this multiline manipulation that comes out of the box with Visual Studio 2010:



I think it will really speed the development. Especially when refactoring old code with lots of lines that need to be manipulated in the same way.

By the way I am sure JustCode team will come out with lots of cool features based on this one ;)

Apr 23, 2010

Sitefinity 4.0 CTP is live!




Kind of late but - check out Sitefinity 4.0 CTP. http://www.sitefinity.com/4.0/asp-net-features.aspx
 
Have a great time playing with it!

Apr 15, 2010

String.Format

Although very convenient for example for making templates and then replace with some values, it may cause tricky problems.

I've reached a code where it was used to add some data to a javascript.
So javascript uses a lot fo curly braces, which are at the same time used for string format to know where to put its values.

There is a way to escape those braces, buy double them, so for example :
function {}
will become
function {{}}

Recently I had the "String was not in a correct format." exception. I tried to debug and found nothing wrong with the string and the values that will be placed.
That was because I was expecting the values to be wrong (null references, something like this) and not the string itself.

Guess what did I discovered after a few minutes of debugging?
It was the string that was corrupted. The problem was that this particullar javascript was in the .ascx file. Someone probably hit the CTRL + K + D so the source was re-formatted, addding some white spaces in between the doubled curly braces.

Be warned that string.Format is kind of fragile when it comes to files that may involve curly braces.