It has been a pain to schedule a Sql Agent Job for SSIS packages by using the new SSIS package step type. The security and permission problems are so complex that we can't figured out how to setup the proxy or account permissions. I have read the MSDN help and some step by step instructions but I have no luck by doing that.
Finally I decided to change the job step type to Operating System (CmdExec) and using the dtexec command to run the package directly. And this solved the permission problem immediately. The Job runs more than happy and we don't have the pain anymore.
Wednesday, 23 January 2008
Tuesday, 15 January 2008
Setup configuration file for a unit test project
It's a common scenario when we need to have a configuration file when doing unit testing, especially for testing a database access object. If the project tested is a Windows application, the configuration in the project is app.config, for a web project it's web.config. The configuration file must be copied to the testing bin folder to read configuration data, with the file name AssemblyFile.dll.config. We could copy the config file to the bin\debug or bin\release folder in the testing project, but then we are maintaining multiple copies manually.
To avoid this, we can take advantage of the Post-build event of Visual Studio. First we need to copy app.config file from testing Windows application project to the root folder of the testing project, or web.config file from the Web project and rename it to app.config. Secondly in the testing project property window, click on Build Events tab, we can then enter the following into the Post-build event command line box:
copy /Y "$(ProjectDir)App.config" "$(TargetDir)$(TargetFileName).config"
This command will copy and rename the configuration file to the target folder automaticallty.
To avoid this, we can take advantage of the Post-build event of Visual Studio. First we need to copy app.config file from testing Windows application project to the root folder of the testing project, or web.config file from the Web project and rename it to app.config. Secondly in the testing project property window, click on Build Events tab, we can then enter the following into the Post-build event command line box:
copy /Y "$(ProjectDir)App.config" "$(TargetDir)$(TargetFileName).config"
This command will copy and rename the configuration file to the target folder automaticallty.
Thursday, 10 January 2008
Reg-less Com component deployment
I was developing a Windows application which uses an Activex control from a third party vendor. I registered the control, made a reference to the component in my project, and the application run very well. I made a ClickOnce deployment for my application and try to run the application from a web page in another computer which doesn't have the activex control registered, I didn't find any luck. The application failed to start.
I noticed after I register the activex control in that computer manually, the application run immediately. It turns out the deployment package doesn't register the activex control automatically. I don't want to register the activex control in every computer of our clients, because the maintenance will become a nightmare.
Then I came across this page when I did some gooling:
http://msdn.microsoft.com/msdnmag/issues/05/04/RegFreeCOM/default.aspx
It talks about how to deploy an activex control without registering it. This is page is just what I need.
I followed the procedure by changing the Isolated property of the COM reference to true. When I run the application locally, I saw the dll file containing the COM component was copied to the bin folder of my project.

After I deploy the application to my website again with the change, I run the application successfully even without the activex control registered.
I noticed after I register the activex control in that computer manually, the application run immediately. It turns out the deployment package doesn't register the activex control automatically. I don't want to register the activex control in every computer of our clients, because the maintenance will become a nightmare.
Then I came across this page when I did some gooling:
http://msdn.microsoft.com/msdnmag/issues/05/04/RegFreeCOM/default.aspx
It talks about how to deploy an activex control without registering it. This is page is just what I need.
I followed the procedure by changing the Isolated property of the COM reference to true. When I run the application locally, I saw the dll file containing the COM component was copied to the bin folder of my project.
After I deploy the application to my website again with the change, I run the application successfully even without the activex control registered.
Wednesday, 9 January 2008
Define a prerequisites download location for Windows ClickOnce deployment
In a .NET Windows application, we can publish the application in a Internet web site and ask users to install it from a web page. One of the prerequisites of my application is .NET Framework 2.0. When I publish the installation files, I initially chose to download prerequisites files from vendors web site, but it didn't work.
Then I chose to download from a specific location, and the download was successful. Is there anything wrong with Microsoft's supporting website? The Microsoft website may be working fine, but our firewall setting could prevent us from downloading from an external website.
This makes me upload the .net Framwork installation package into our own website and then I am sure the downloading is guaranteed.
Then I chose to download from a specific location, and the download was successful. Is there anything wrong with Microsoft's supporting website? The Microsoft website may be working fine, but our firewall setting could prevent us from downloading from an external website.
This makes me upload the .net Framwork installation package into our own website and then I am sure the downloading is guaranteed.
Tuesday, 8 January 2008
Use Application.ThreadException event to catch unhandled exceptions in a Windows Forms application
Application.ThreadException event occurs when an unhandled exception is thrown, based on MSDN. To avoid your Windows application from crashing when an exception is not caught by your code, you should attach your own event handler to this event in program.cs file.
The following code shows how this works:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(UnHandledException);
Application.Run(new MainForm());
}
static void UnHandledException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message);
}
Note the event handler should be attached before the Application.Run method.
The following code shows how this works:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(UnHandledException);
Application.Run(new MainForm());
}
static void UnHandledException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message);
}
Note the event handler should be attached before the Application.Run method.
Monday, 7 January 2008
Scroll a Windows Form DataGridView to a specific row
I have a Windows Form which contains a TextBox and a DataGridView. When a user enters anything I need to do a search and make the grid scroll to the row matched.
I was struggling for a while for the scrolling until I came across this property: FirstDisplayedScrollingRowIndex. It's simple, just assign the row index value to this property and the grid will scroll to the row and show the row as the first row in the visible area.
I was struggling for a while for the scrolling until I came across this property: FirstDisplayedScrollingRowIndex. It's simple, just assign the row index value to this property and the grid will scroll to the row and show the row as the first row in the visible area.
Friday, 4 January 2008
.NET Interview Questions (6)
Developers using XML
· What is the purpose of XML Namespaces?
XML Namespaces remove conflicts between different documents from different sources.
· When is the DOM appropriate for use? When is it not? Are there size limitations?
Dom is appropriate for small document and the document needs to be modified. It’s not appropriate for big document because of performance issue. There is no size limitation as long as there is enough physical memory.
· What is the WS-I Basic Profile and why is it important?
· Write a small XML document that uses a default namespace and a qualified (prefixed) namespace. Include elements from both namespace.
· What is the one fundamental difference between Elements and Attributes?
Element can contain another elements and attributes. Attributes can only reside inside an element.
· What is the difference between Well-Formed XML and Valid XML?
Well-Formed XML follows xml grammar. Valid XML is validated against xml schema or dtd. A valid xml is well-formed. A well-formed xml might not be valid.
· How would you validate XML using .NET?
Using XmlValidatingReader class.
· Why is this almost always a bad idea? When is it a good idea? myXmlDocument.SelectNodes("//mynode");
This statement returns all elements under mynode. This could return a large amount of data. It’s more efficient to use SelectSingleNode method and pass a full path, or use SelectNodes with a relatively deeper path.
· Describe the difference between pull-style parsers (XmlReader) and eventing-readers (Sax)
In XmlReader you control the parsing and define which element to go to. Sax parses the Xml internally, and raises events whenever it find something interesting.
· What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
XpathDocument is not editable. XmlDocument is editable. XpathDocument is used for fast readonly situation. XmlDocument is used when the document needs to be changed.
· What is the difference between an XML "Fragment" and an XML "Document."
XML Fragment is not a full xml document. It doesn’t have element.
· What does it meant to say “the canonical” form of XML?
The purpose of Canonical XML is to define a standard format for an XML document. Canonical XML is a very strict XML syntax, which lets documents in canonical XML be compared directly.
Using this strict syntax makes it easier to see whether two XML documents are the same. For example, a section of text in one document might read Black & White, whereas the same section of text might read Black & White in another document, and even in another. If you compare those three documents byte by byte, they’ll be different. But if you write them all in canonical XML, which specifies every aspect of the syntax you can use, these three documents would all have the same version of this text (which would be Black & White) and could be compared without problem. This Comparison is especially critical when xml documents are digitally signed. The digital signal may be interpreted in different way and the document may be rejected. Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?
· Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?
Both are used for defining the rules of an xml document. DTDs are written in regex, XSDs are written using xml.
Document Type Definition (DTD) describes a model or set of rules for an XML document. XML Schema Definition (XSD) also describes the structure of an XML document but XSDs are much more powerful. The disadvantage with the Document Type Definition is it doesn’t support data types beyond the basic 10 primitive types. It cannot properly define the type of data contained by the tag. An Xml Schema provides an Object Oriented approach to defining the format of an xml document. The Xml schema support most basic programming types like integer, byte, string, float etc., We can also define complex types of our own which can be used to define a xml document. Xml Schemas are always preferred over DTDs as a document can be more precisely defined using the XML Schemas because of its rich support for data representation.
· Does System.Xml support DTDs? How?
Yes, in addition to XDR and XSD schema validation, .NET continues to support the DTD to validate the XML documents. The System.Xml namespace contains a class named XmlValidatingReader that can be used to validate the XML documents.
· Can any XML Schema be represented as an object graph? Vice versa?
Yes.
Subscribe to:
Posts (Atom)