Blog Stats
  • Posts - 42
  • Articles - 0
  • Comments - 61
  • Trackbacks - 36

 

Tuesday, May 02, 2006

techEnvelope.com

Helo all, I've migrated my blog to http://www.techenvelope.com/
Posts about technology, code and more will continue there.
So update your bookmarks to tech:Envelope

Thursday, March 09, 2006

My experiences with Visual Studio.Net 2005

In Visual Studio.Net 2005 things have changed quite a bit. For better. But for people who resist changes, they're gonna have some starting trouble. Like the following ones. For me. May be for you as well.

Problem 1:
I want to run my webservices under IIS, not on a developement server with some port (For ex: 4187) which kicks off while debugging (when you press F5).

Solution:

  1. Right click on the project (there's no really a project there in your solution explorer. Its just a directory structure like C:\...\MyWebSvc\) click Build site.
  2. Go to windows explorer right click on this directory (MywebSvc) web share it. Go to IIS, Go to the default web site -> MyWebSvc right click properties -> Remove application -> Create application. Say apply. Done.
  3. Now you can run http://localhost/MyWebSvc/Service.asmx and attach this as webreference to your other project (which uses the websvc) so that your other team members can use this websvc which is now setup on your machine. Make sure you change "localhost" to your machine name, when you web reference it in another project.

Ideally this is exactly what might have to be done on a production web server. I am not sure what the publish site does. Need to check it out though.

Problem 2:
As explained in the Solution above, I am not really comfortable with the idea of having a directory structure for WebSvc or ASP.Net website, without a .csproj.
Can someone tell me what's the purpose and how better to get used to it?

Problem 3:
This is not completely related to VS.Net 2005 but still I would like to put it this way. I have a web service running on my machine, which talks to a SQL server db using windows authentication of my machine. When I run this websvc from my machine all goes fine. Now my other team members run this websvc from their machines, the SQL server login fails. Even I run it from my webbrowser (not in debug mode, not through the dummy dev server) it fails.

Solution:
You have to impersonate the aspnet_wp worker process to use your windows authentication, which can be done by adding the following nodes to your web.config of the MyWebSvc.

<authentication mode="Windows" />

<identity impersonate="true" />

Problem 3.1:
Now with the above problem 3 solved, you have one more minor problem, when you run this websvc from IIS, you want to debug it. So you attach aspnet_wp.exe to your project in the visual studio. But just when you open the SQLConnection (SQLConnection.open), throws an exception
[SqlException: EXECUTE permission denied on object 'sp_sdidebug', database
'master', owner 'dbo'.]
But, if you have handled this exception without rethrowing it, rest of the code works fine without a problem.

Solution:
While attaching the aspnet_wp.exe process, just make sure you've changed the "Attach to:" to work on only "Managed code", just uncheck the "T-SQL code".
Now you won't get an exception while debugging. Check out for more info on this problem.

Wednesday, March 01, 2006

String replace in XSLT

It is possible to do string manipulation like replace etc in XSLT as well. Javascript has str.replace right? So in XSLT you can do this by creating templates and by doing call-template.

Follow this link for complete info and source code
http://www.dpawson.co.uk/xsl/sect2/StringReplace.html

Wednesday, February 08, 2006

Getting a stream object from a MyJavascript(.js txtfile) - Resources

// Getting a stream object from a MyJavascript(.js txtfile) in the Resources.

// In VS-2005 > .Net 2.0

objMyStream = new System.IO.MemoryStream(

                System.Text.Encoding.UTF8.GetBytes(

                    Properties.Resources.MyJavascriptFile));

Monday, February 06, 2006

LOTD # 1 : Check the InnerException

Today, one of my teammate was getting a "TargetInvocationException" : Exception has been thrown by the target of an invocation. This reminded me of my 'initial learning curve' days in .Net when I encountered this exception, and had a really hard time fixing this one. I can't remember how we(There were other team members who worked on this as well and it was back in 2002-03) solved it.

The beauty of the problem is you wouldn't know why you are being thrown this one, inspite of things working as they should.

The lesson learned is to do in-depth (F11) debugging and check for the InnerException when you catch it (always use try catch around potentially functional code). It will excatly tell you what's wrong. Print it out (Console.WriteLine) on the output window and you'll know.

LOTD: Lesson Of The Day is a series starting on my blog.

Wednesday, February 01, 2006

File path in C#

When you have to pass in a file path to do some processing with the file, try using the following C# code.

string path = Path.Combine(Environment.CurrentDirectory, @"..\..\TestDeserialization.xml");

Where,

The TestDeserialization.xml file is in the Project root directory.

It helps to avoid confusion in file paths.

Thursday, January 26, 2006

The "true" Checklist for XML Performance

http://monkey.workarea.jp/lb/archive/2005/8-08.html

 

The Hanselman List of .NET Debugging Dos and Don'ts

Don't - Say "Hey, I got a NullReferenceException," what's the problem?
Do - Provide a Stack Trace/Dump with the line number it likely happened on.

Don't - Get deep into your complicated program, find a bug and insist it's BillGs fault.
Do - Reproduce the bug in some simple test program and tell the world. Remember, 9/10 times it's you.

Don't - Decide there's a problem if you don't know the preferred behavior.
Do - Always Assert your assumptions. If null can happen, check for it. BUT, if null must never happen it's time for a Debug.Assert

Don't - Move code around blindly, somehow fix your bug, ignore it and keep coding. Programming by Coincidence!
Do - Understand your program fully. Remember what Andy and Dave say about lucky folks who step into minefields and don't die. Just because you didn't die, doesn't mean there aren't mines!

Don't - Reformat or "pave" something because you don't know what's wrong. If you get a spot on your carpet, fix the spot. Don't lay new carpet.
Do - Know enough about your environment to know what your program's dependencies are. If your registry settings can get boogered, Debug.Assert that you are getting good values from the registry.

Don't - Get overly frustrated with Assembly loading/versioning/policy. At least the Assembly Loader follows clear, set, rules.
Do - Make a folder called C:\FusionLogs, then go to the registry in HKLM:\Software\Microsoft\Fusion and make a DWORD value LogFailures=1 and string value LogPath=C:\FusionLogs. Every AppDomain that has a binding failure or weird redirect will get logged. Know: What assembly you want, what they looked for, what you got. Know where Assemblies are searched for.

Don't - Avoid debugging. Debugging in .NET is easier than ever before. Remote debugging and AttachToProcess are gifts. Don't stop at a point in the call stack if you can keep going by finding PDBs.
Do - Keep your Source and PDBs in the same location. We keep ZIPs of every build's PDBs. Just today we dug up 9-month old PDBs and source (from CVS) to debug into some confusion. Not saving those PDBs would have screwed us. Create a Symbol Server.

Don't - Limit yourself to the QuickWatch. Learn what VS.NET has to offer.
Do - Use the Immediate Window to test theories. Remember that you can perform Casts in the Watch Window. Remember that you can drag and drop variables into the Watch Window. Remember you have 4 Watch Windows, Autos, Locals, not to mention. Learn how to use Conditional Breakpoints!

Don't - not debug something just because you can't figure out how to launch the process from the VS.NET Project Properties.
Do - Debug|Processes|Attach to attach to processes that have your DLL loaded. Use ProcExp from SysInternals as a better Task Manager to see .NET processes, as well as a system-wide DLL search. Who's got you loaded?

(via Scott Hanselman)

Friday, January 20, 2006

XML datatype in SQL server 2005 - just be sure

In my last post I mentioned that SQL Server 2005 provides with you with the flexibility of having an XML document stored into one single column of “Xml” datatype. Just like a int, datetime or a nvarchar() datatype, you can define “Xml” datatype to store the whole Xml document or a fragment as long as your XML is valid.

But the catch here is if your XML file has a header something like “ “, and you are sending this document as a string to the database, you are in trouble. You are presented with an exception something like “XML parsing: line 1, character 38, unable to switch the encoding”.

So the solution is, while you are opening the FileStream, open with a second parameter “Encoding.Unicode”. That's it. So now your XML document is going to be stored in Unicode (UTF-16) format. However when you retrieve it back from database, remember to convert it to UTF-8, if you are expecting it.

It pays to use http://groups.google.com

Check out limitations with “XML datatype“ in SQL server 2005

Update: Or better still, you are better off using the following.

m_sqlCommand.Parameters["@XmlDocument"].Value = new SqlXml(new XmlTextReader(xmlDocumentToPush, XmlNodeType.Document, null));

Friday, October 07, 2005

Learning COM+ components

  1. Create a class inherited from ServicedComponent class by referencing System.EnterpriseServices.
  2. Write the logic in it and declare methods.
  3. Add class hierarchy as necessary.
  4. Compile the project.
  5. Go to command prompt and on to the bin\debug folder, and type in
     sn -k CalculatorServiceComponent.snk
     This is to strong-name and write the key pair to the .snk file.
  6. Move the .snk file to the root of the project folder.
  7. Have the following line in the AssemblyInfo.cs file of the project.
     [assembly: AssemblyKeyFile("..\\..\\CalculatorServiceComponent.snk")]
  8. Go to command prompt again and run,
     regsvcs CalculatorServiceComponent.dll
  9. You might get couple of warnings, which can be ignored depending on the severity.
  10. Go to Component services from control panel and look up the created COM+ components and the methods that have been defined.

Friday, January 20, 2006

Starting a business - a thought

“Don’t start a business if you can’t explain what pain it solves, for whom, and why your product will eliminate this pain, and how the customer will pay to solve this pain. The other day I went to a presentation of six high tech startups and not one of them had a clear idea for what pain they were proposing to solve.”

(via Joel on software)

Wednesday, January 18, 2006

SQL Server 2005 express - connection problem

At work I got installed the new SQL server 2005 express edition, with VS.Net 2005. Through the Visual Studio's server explorer I was unable to connect to my SQL express. After trying different things, I downloaded the SQL Server Management Studio Express CTP. But it had so many runtime bugs, that I couldn't help stop using it.

I even tried setting up the TCP/IP and NamedPipes protocol to 'enabled' in the Configuration management tool of SQL server 2005. This is done to enable remote connections.

After doing a lot of search on the internet, finally found the solution to this problem.

When you connect through the Visual Studio 2005 server explorer, you need to specify “.\SQLExpress” as the server name as opposed to “yourservername” or “(local)” or “SQLExpress”. Simple solution but bad problem.

I am on SQL server 2005 express now, right within the VStudio and the tool is damn good and fast.

Note: On a different note, SQL server 2005 has special “Xml” datatype which you can use to store XML documents, and dynamically “XQuery” them and setup relational database type of functionality. I am going to explore it now.

Monday, November 14, 2005

Design Patterns reference

Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges. 

The Gang of Four (GoF) patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral. Here you will find information on these important patterns.

To give you a head start, the C# source code is provided in 2 forms: 'structural' and 'real-world'. Structural code uses type names as defined in the pattern definition and UML diagrams. Real-world code provides real-world programming situations where you may use these patterns.

A third form, '.NET optimized' demonstrates design patterns that exploit built-in .NET features, such as, attributes, events, delegation, and reflection. These and much more are available in our unique Design Pattern FrameworkTM. For an example of a .NET optimized pattern see our Singleton page.

  Creational Patterns
  Abstract Factory   Creates an instance of several families of classes
  Builder   Separates object construction from its representation
  Factory Method   Creates an instance of several derived classes
  Prototype   A fully initialized instance to be copied or cloned
  Singleton   A class of which only a single instance can exist

  Structural Patterns
  Adapter   Match interfaces of different classes
  Bridge   Separates an object’s interface from its implementation
  Composite   A tree structure of simple and composite objects
  Decorator   Add responsibilities to objects dynamically
  Facade   A single class that represents an entire subsystem
  Flyweight   A fine-grained instance used for efficient sharing
  Proxy   An object representing another object

  Behavioral Patterns
  Chain of Resp.   A way of passing a request between a chain of objects
  Command   Encapsulate a command request as an object
  Interpreter   A way to include language elements in a program
  Iterator   Sequentially access the elements of a collection
  Mediator   Defines simplified communication between classes
  Memento   Capture and restore an object's internal state
  Observer   A way of notifying change to a number of classes
  State   Alter an object's behavior when its state changes
  Strategy   Encapsulates an algorithm inside a class
  Template Method   Defer the exact steps of an algorithm to a subclass
  Visitor   Defines a new operation to a class without change

Source: http://www.dofactory.com/

Tuesday, October 18, 2005

AJAX presentation

I gave a presentation on AJAX today. It was a knowledge sharing session at my company. Around 35 people attended the session. Though quite a few appeared silent and uninterested, there were some who were interested.

Update:

I got some valuable feedback on my presentation, which is as follows.

1.  You have good knowledge on the topic, you could have connected with the audience much more.. get them more involved.. by asking simple questions and asking for opinions..  You need to remember that, by being on the stage, you are looking to influence people to buy what you are saying.
2.  The transition effects in the slides is not really a part of the template, so, you must have added it.. sometimes, these could be disturbing, as they have the potential to take away audience's attention from what you are saying to what they are seeing on the screen.  So, if at all, use of these effects should be minimal, to help spice up the presentation at key points only.
3.  Some of the slides had long sentences in them.. I think it is not such a good idea.. we should look to have very short and crisp phrases, to be used by you as a hint to talk on the topic.  If and when audience sees a sentence like this, again, you are losing their attention, as they start reading it.. and also, you are losing eye contact with them since, you also tend to read it from the screen.

I am going to make sure I follow the suggestions in the feedback.

Friday, September 23, 2005

AJAX Dictionary

This is one more super duper example for the power of AJAX (Asynchronus Javascript And Xml). We had GMail, Google Suggest, Google Groups, GMaps etc already showing the power of it. I had already tried it out for a Pubs database using C#, just like Google suggest. But the dictionary idea is real good.

Check it out: http://www.objectgraph.com/dictionary/

How does it work: http://www.objectgraph.com/dictionary/how.html

 

 

Copyright © Vinayak