Wednesday, January 30, 2008

Reversing a String using C#... why not?

After doing a lot of coding and finally getting my program to do what I wanted I decided to take a break and try something new (for me).

One thing I never had to do for any application is reverse a string. As with anything I never did before I decided to give it a try, so I cooked up a few functions.

Reverse1 below is the most basic way of doing it, but is the slowest. Since in .NET string are immutable (See Jon's Article for details) each time we concatenate it will create a new string object to keep our updated text. This can be very slow for large text blocks.

Reverse2 is a StringBuilder version which uses the power of mutable strings to avoid our performance problem above.

Reverse3 is an example I found trying to look for alternatives to my first two functions. (Thanks Justin Rogers for your post)

My Reverse String Examples

private static void Reverse1()
{
string Data = "hello world";
string Data2 = string.Empty;

// Reverse using strings
for (int i = Data.Length - 1; i >= 0; i--)
{
Data2 += Data.Substring(i, 1);
}

Console.WriteLine("Basic Strings: " + Data2);
}

private static void Reverse2()
{
string Data = "hello world";
StringBuilder sb = new StringBuilder();

// Reverse - String Builer for Performance
for (int i = Data.Length - 1; i >= 0; i--)
{
sb.Append(Data.Substring(i, 1));
}

Console.WriteLine("StringBuilder: " + sb.ToString());
}

private static void Reverse3()
{
string Data = "hello world";
char[] DataArray = Data.ToCharArray();

Array.Reverse(DataArray); // reverse
string Output = new string(DataArray); // back to string

Console.WriteLine("Array Reverse: " + Output);
}

Monday, January 28, 2008

What is a screencast?

Today a friend of mine asked me "What is a screencast?". I get this question often from fellow developers and finally decided to create a blog entry I can reference going forward to answer the question.

Screencast concept is best defined by Wikipedia entry:

Screencast is a digital recording of computer screen output, also known as a video screen capture, often containing audio narration. Although the term screencast dates from 2004, products such as Lotus ScreenCam were used as early as 1993. Early products produced large files and had limited editing features. More recent products support more compact file formats such as Macromedia Flash and have more sophisticated editing features allowing changes in sequence, mouse movement, and audio.

Just as a screenshot is a picture of a user's screen, a screencast is essentially a movie of what a user sees on their monitor.

Now that we have the formal definition, let me provide some very good examples of .NET technology related screencasts:

In my own words screencasts are an excellent way to learn how to program or use various tools in a visual environment. If you Google this term along with a topic of interest the odds are you will find some content.

Enjoy!

SQL-CLR Stored Procedures - Cannot talk to Visual Studio Output Window?

Today while debugging a SQL-CLR stored procedure written in C# (using VS 2005) I came upon a frustrating issue. It seems I cannot do things like:

  • Debug.Print
  • Debug.WriteLine
  • Debug.Write
  • Console.WriteLine
  • Console.Write

Scenario #1: Starting Debug with Console.WriteLine statement in code I immediately get this error

The protected resources (only available with full trust) were: All

The demanded resources were: UI

Scenario #2: While running debug I hit debug.print line and get this error

The protected resources (only available with full trust) were: All

The demanded resources were: Synchronization

This sort of makes sense to me as these statements are trying to use library api's that are purely visual and would not work without an attached debugger. (There is no Console or Debug window when running this purely in SQL Server 2005)

Alternatives?

SqlContext.Pipe.Send is another way to communicate out to the output window but I am fairly new to this statement and it seems to send output in bulks.

Honestly I am not sure of another work around at the moment but I hope this information at least helps.

I am all open to ideas and workaround so please send them to me or post them as comments.

Moving Forward: Learning .NET 3.5, VS 2008 and C#

Its time for me to seriously jump into .NET 3.5, VS 2008, and C# 3.0. I will be honest, there are still some things I need to learn about C# 2.0 but such is life, one must move forward.

Today I accidentally stumbled upon .NET 3.5 Books from apress. I cannot speak for these books personally as I have not seen any of them, but judge for yourself.

skeet_cover150For C# addicts like myself I also strongly recommend my friend Jon Skeet's .NET book which is coming out in the very near future. It is titled C# in Depth and the first chapter is already online and it will have you hooked. Here is the table of contents for his book if anyone is interested:

C# In Depth Tables of Contents

Part 1: Preparing for the journey
1. The changing face of C# development - FREE
2. Core foundations: building on C#1

Part 2: C# 2 - Solving the issues of C# 1
3. Parameterized typing with generics 
4. Saying nothing with nullable types 
5. Fast-tracked delegates 
6. Implementing iterators the easy way 
7. Concluding C#2: the final features

Part 3: C# 3 - Revolutionizing how we code
8. Cutting fluff with a smart compiler 
9. Lambda expressions and expression trees 
10. Extension methods
11. Query expressions and LINQ to Objects
12. LINQ beyond collections
13. Elegant code in the new era

Microsoft SQL Server: SQL-CLR Project Template in VS 2008

I recently got assigned a task to asses the ease of developing SQL-CLR Stored procedures to run in SQL Server 2005. Since I am a big fan of Visual Studio 2008 I had decided to first see if this can be easily done using the new VS 2008 IDE.

image I was immediately able to find what I thought was a new project template I have never seen before under the name SQL-CLR (as seen in the screenshot to the left)

Before I jump to excitement of a new feature I took another more detailed look at VS 2005 and found it also had this project type, it is merely not found under the Database Projects tree. Instead this template is located under the language specific trees (in my case Visual C#) as seen in the screenshot below.

image

Nonetheless I decided to continue working with VS 2008, but found something very confusing...

image

SQL Server Project on the left, SQL Server Project on the right, I was puzzled. What is the difference? I decided to try the left one and discovered it made a VB.NET SQL-CLR project. This is not what i wanted so I tried the right one, and it was the C# version I required.

While it might be clearer on the large screenshot above that the Icons are the main indicator for the language, trust me it was not that clear on the high resolution I am using.

smile_sarcastic

I hope this posts saves someone a few minutes of confusion in the future. The projects themselves work great and I am already prototyping making C# CLR Stored Procedures.

The one last puzzle I have, can SQL CLR in SQL Server 2005 support .NET 3.5 (C# 3.0) language features? My gut feeling is saying no at this point and the limited amount of referenced assemblies is a good hint in that direction. (with no obvious way to expand on that list)

image

If someone has contrary information I would love to hear from you in comments or email feedback.

Saturday, January 26, 2008

.NET CLR Profiler: Waiting for application to start common language runtime

Today I decided to try a tool called CLR Profiler. If you never heard of this tool before, here is what MSDN says about it:

The CLR Profiler includes a number of very useful views of the allocation profile, including a histogram of allocated types, allocation and call graphs, a time line showing GCs of various generations and the resulting state of the managed heap after those collections, and a call tree showing per-method allocations and assembly loads.

My first step in using the tool was to download it, so I Googled the words "CLR Profiler" and the very first link took me to the download page for "CLR Profiler (v1.1)".

For about half a second I wondered "Does v1.1 mean its for Framework 1.1?", but that thought passed and I wrongly assumed it was merely a version number coincidence. That was a mistake on my part.

image

I started the tool and used the "Start Application" button with all the default settings to try and profile a very basic application I had built specifically for this purpose. Doing so though did not seem to work, the profile would get stuck on the message "Waiting for application to start common language runtime" and after I would exit my test application, CLR Profiler would crash.

image

image

Puzzled by this I went back to the download page for the profiler and quickly discovered the problem, my original thought should have been pursued, this really was the profiler for .NET Framework 1.1! A link at the bottom of the download page pointed to the correct version: CLR Profiler for the .NET Framework 2.0.

Now that I am using the correct version of the utility it works perfectly. It is worth noting though that the interface really looks the same between the two versions, so don't let that fool you either.

 CLR Profiler 2.0 CLR Profiler 1.1
image image

Friday, January 25, 2008

Microsoft: More platform centric then ever

One thing Microsoft does well is build a platform for others to expand upon. This is evident by simply looking at Office, their #1 money maker.

Microsoft Office is not a simple set of tools for editing text (word) or number-crunching (excel). Instead its a platform that lets people script (using VBA), record (using Macros) or even store relational data (using Access). Between Excel and Access hundreds of thousands of applications exist that were not created by hardcore programmers but instead thousands of novice hackers who took advantage of the products scripting functionality.

Looking beyond office there is of course the biggest platform; Microsoft Windows itself. Think of all the hardware it runs on and all the applications it supports. Microsoft really did a great job at opening it up for both hardware and software vendors that has lead to Windows domination in the marketplace.

For the more Hardware Core developers Visual Studio is an amazing platform to rapidly build applications. Again Microsoft has not only made a development tool with a set of languages but instead made Visual Studio itself a platform for developers to build GUI driven experiences. Visual Studio can be extended ranging from plug-ins to SDK-driven integrations that allow for total customization of the environment.

Today Microsoft's products seem to all head into this general direction of opening and providing a platform. Here is my list of some notables examples:

Application Platform Capabilities
Visual Studio 2008 Shell Edition Visual Studio IDE can now be totally customized to support any language or development purpose. You can also take advantage of the Visio style designer to create UI driven tools.

You can then distribute your custom integration so that it integrates into Visual Studio 2008 installations or as a stand-alone module that can be totally re-branded and even SOLD under your name.
Live Writer SDK This blog post was created using Live Writer, a tool that not only supports Microsoft Live Spaces blog service but others such as blogger.

Another great feature of Live Writer is the ability to create plug-ins to further extend the functionality to support ANY service, including Microsoft competitors. (Example: Flicker)

Microsoft even hosts these plug-ins on a gallery page for easy distribution. 
Silverlight Silverlight 1.0 is a competitor product for Flash for interactive media and video streaming. This browser plug-in is supported by Microsoft for Windows and Macintosh. Microsoft has also partnered with a 3rd party to develop the plug-in for Linux.

Coming in 2.0 (formerly known as 1.1) Silverlight is becoming a full-fledged cross-platform development environment hosted inside of a browser. It will support C# and VB.NET application development and will probably revolutionize how Microsoft centric developers build web-pages and interactive applications.
Microsoft Expression Suite Microsoft Expression suite is the first real attempt at Microsoft to build a platform for Graphic Artists that integrates with Visual Studio development. This expands the possibilities of never before seen levels of cooperation between designers and developers.
Microsoft .NET Source Code Release Microsoft is opening up its .NET Source code and it is now fully integrated with Visual Studio for debugging.

One could criticize me for being fairly broad in my definitions of a platform, but these are definitely all examples of the same general principals talked about earlier.

Microsoft is a changed organization that I believe will continue to open and innovation. The future looks bright for all involved.

Thursday, January 24, 2008

Geek Humor

http://www.songless.com/blog/2007/05/30/programming-lolcats/

I will say no more, just go read it and laugh a little.

Warning: Programmer geeks only...

Solaris Online - Early Alpha

solarisanim

One of my close friends is a very good software engineer in the financial sector. While his day job might be dealing with numbers he spends his nights working on a multi-player game written in Visual Basic 6.

Why VB6? While he is not married to Visual Basic 6 (out of all languages) he has made significant progress over the years working out DirectX issues, creating a physics engine, and working out a very fast networking component. Re-writing it all in another more modern language would be time consuming and at this point wasteful.

The game has finally hit enough stability that it is available for public download in early Alpha. Go download a copy and check it out for yourself!

Download the client at: http://www.solarisgame.com/

Notes

  • Since this game is not really well know yet you will usually find multi-player working but the game void of people. Monday nights around 8pm is a good time though to catch a live test with the creator himself
  • There is no patch warning, you should always uninstall the old version and reinstall the copy from the website before playing
  • In the near future I will help my friend setup a blog and calendar for the game so things can be better coordinated

Wednesday, January 23, 2008

Temporary Password at Public Terminals

During lunch today I had an interesting thought. I can't claim this is a 100% original idea (especially since I listen to Security Now! podcast) but originality aside I think this is a MUST have feature for email systems.

The idea itself evolved from a problem with my iPhone earlier in the day; it locked up. This lead me to consider that I do not know most of the phone numbers on the phone so if it dies and I need to contact people I wont be able to. I then realized I could simply find any paid Internet kiosk in the City and use Gmail profiles to retrieve the phone numbers.

What scares me about such Kiosks though is spyware or specifically key stroke loggers. How can I trust these places not to compromise (from keyboard entry) my email accounts on Gmail or Live Mail?

This spawned the idea of a temporary password.

Temporary Passwords Text Messaged to Cell Phone

My idea involves an additional setting in gmail/Live Mail that would allow me to associate a cell phone number with the account.

I would then have an option at the login screen to request a temporary password be text messaged based on me entering a valid username. (Potential Issue: What stops people from spamming phones? hmm)

The emailed password would need to expire fairly quickly and definitely die after one valid login to the account.

To further protect the email in this login scenario HTTPS should be enforced for the entire session when logged in using the temporary password. Consideration would also need to be given to:

  • Preventing the spoofing of this session while the users is still active
  • Length of session, perhaps a shorter session should be used (time from inactivity to session death)

Conclusion

Again this is not an original idea, but I have never seen any email system implement it as I describe above. It really should not be that hard to do and I would gladly accept a job at either Google or Microsoft to help them implement it.

smile_shades

This feature would make me a LOT more comfortable on using various email systems from public terminals or even other peoples machines.

The funny thing is this idea would not work for my very original train of thought, as in that scenario my cell phone dies LOL.

Have a comment? Please feel free to post it on this thread!

Adding Immediate Window into Interface

Today I posted an issue with the Immediate Window option being missing from the interface. After playing with Visual Studio 2005 I figured out how to add it back. Here is the step-by-step instructions:

Step #1

image

Start Visual Studio 2005.

Go to Tools, then select Customize..

Step #2

image

Select the Command Tab, and find Debug from the Categories menu. Once you have clicked on Debug in the menu scroll through the commands on the right until you see Immediate.

Step #3

image

Drag the Immediate command by left-clicking (and holding the mouse button down) on it, then move your mouse into Debug > Windows > and drop it under the last command (in my case Breakpoints).

You can really place this button anywhere in the menu or toolbars, but I like it in the default location as shown above.

Step #4

image

Press the Close button to save your interface change.

Done

image

You should now see the Immediate option available from the menu or CTRL-ALT-I shortcut.

The missing Immediate Window

The Immediate Window is a very useful console in Visual Studio, here is an excerpt of what it does from MSDN:

The Immediate window is used at design time to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.

Unfortunately this window seems to be missing from the menu system. Before wasting a good 10 minutes today looking for it I could have sworn it was a menu option in Visual Studio 2005, but no luck.

imageAfter doing some research I finally located on the command which opens the Immediate Window from the Command Window by typing "immed" and hitting enter.

Immediate Window Screenshot

image 

If anyone knows a better way of opening this window please let me know.

iPhone Web apps

I recently discovered that Apple has a list of what they call "Web apps" on their website. These are merely websites designed to work with the iPhone and most of them are fairly crude. Some though hold great potential, here are my top picks so far:

  • FlyTunes: Streaming audio to your iPhone. (Currently not allowing new users to sign-up but you can register for future access)
  • Podcaster: Allows you to listen to various popular MP3 formats as an audio stream. Works really well over wifi.
  • Tittr: Allows you to post pictures from your iPhone by emailing them to a specific URL that acts as an upload point

There are over 700 app's posted and I stopped at page 16. Look through the complete list yourself at the following URL:

http://www.apple.com/webapps/

Tuesday, January 22, 2008

Microsoft SharedView Beta 2

sharedview_beta2For a long time now I have really wanted a large company to release a well made and free product that would allow meetings over the Internet with shared desktops. While many products (including commercial ones like WebEx) exist I have never been able to find a descant free alternative, until today.

This product is fairly well hidden but Microsoft is now in Beta 2 of SharedView. SharedView Beta 2 allow you to share your application or desktop with anyone you want within your virtual meeting, and has many exciting features. Here is the list so far:

  • Sharing your application or desktop
  • Allow others to take control
  • Previewing what attendees see to ensure you are not sharing something accidentally
  • Handing out virtual documents to everyone using the Handouts feature
  • Integrated with Live ID, so one less login to remember
  • Its Free

Did I mention its free? Go check it out for yourself!

http://get.live.com/betas/sharedview_betas

(p.s. I have used and hated WebEx for a long long time now... anything that comes along and gives it a real reason to improve or die is welcomed)

SSIS: Reading and Setting package variables using C#

There are many occasions when an SSIS package has User Defined Variables that need to be modified at runtime by C# code. Here is an example that both reads and sets such variables.

Example: Reading and Setting Package Variables

// Set the path to your package file (.dtsx extension)
string PackagePath = @"c:\SSISPackages\MyPackage.dtsx";


// Create Application Instance and Package placeholder
Application app = new Application();
Package p = null;

// Load the package
p = app.LoadPackage(PackagePath, null);

// In this example i want to change the variable that holds the
// path to my source file
p.Variables["SourceFilePath"].Value = @"c:\SourceFiles\testdata.xls";

// Execute my package
p.Execute();

// My package sets an internal variable that i want to
// pull out, this is how i do it
string InsertedKey = p.Variables["InsertedKey"].Value.ToString();


Note: You will need to add a reference to Microsoft.SQLServer.ManagedDTS assembly and add the using Microsoft.SqlServer.Dts.Runtime; namespace reference in order to make this sample work

Saturday, January 19, 2008

Centralized Login System

Windows Live ID is Microsoft's premier centralized login authentication system. The danger with such systems is if they go down they impact all the applications that use them. In my particular case Live OneCare subscriptions page become unavailable due to just such a problem, see screenshot below.

image

Hopeful that perhaps using another entry URL into Live OneCare subscription will get around this problem I tried their link from the front page, instead of using the software "subscribe through the webbrowser" button. No luck again.

image

This is extremely distributing. Windows Live ID is now the only way I can authenticate to various Microsoft Live related products and downtown is just not acceptable.

Hopefully this is just an isolated occurrence and Microsoft can get their act together. So far though the login has been down for more then two hours, I guess Microsoft is not going to get my money today.

UPDATE 1/20/2008

image

This error persists so I have reported it to Microsoft support. Lets hope it gets action now.

Thursday, January 17, 2008

Microsoft Developer Centric Magazines

February08Coverlg Today we engineers live in a fortune time as many educational options are available to enhance our development knowledge. Complexity is all the rage making these options even more necessary for anyone trying to stay "in the game".

Today I want to shed some light on the various options available in magazine print format, here is my list:

Publication Price*
MSDN Magazine 1 Year $34.95
2 Year $59.95
Visual Studio Magazine

If you live in the United States and are an IT professional this print magazine is FREE.

If you do not, the prices are as follows:

1 Year US Non-IT Pro $34.97
1 Year Canada/Mexico $52.97
1 Year All Other $78.97

Microsoft Architecture Journal
Free
Code Magazine 1 Year (6 issues) $29.99

* Prices are as of Jan 17th, 2008 as published on each magazines website.

MSDN Magazine

This is a magazine I subscribe to myself and really enjoy. While it does not always cover the topic I personally want its range of content is excellent. Its published by Microsoft itself and always has many MVP's and .NET community leaders contributing cutting edge information.

MSDN magazine only charges for its print edition. You can freely view all articles and download the source code on their website. Click Here for an example of the February 2008 issue.

Visual Studio Magazine

I do not subscribe to this magazine and therefore cannot speak about it. Luckily it also publishes it articles online for free, so visit their website and check it out for yourself.

Microsoft Architecture Journal

This is an excellent publication centered around Architecture topics and discussion. I receive it and while its a thin publication its content is a great source of information compared to the (free) price tag.

imageJust like MSDN Magazine and Visual Studio Magazine the trends seems to indicate the need for full and free online content and this magazine does not disappoint. Not only does it publish its content online but it also provides a cool Journal Reader application, check it out!

Code Magazine

This is a popular independent (from Microsoft) magazine, but as I have never even seen an issue I cannot judged it. Click Here and check out their free online content for yourself.

Conclusion

These magazines are an excellent way to try and keep up with technology, and many are available for free in print (while all are available for free online). There is NO excuse anymore for not at least trying to read an article or two a month if your serious about what you do.

Wednesday, January 16, 2008

Upserts (Updates and/or Inserts) using SSIS into SQL Serve

My current challenge while learning SSIS is how to handle more complex data scenarios when straight bulk data insert is not the only requirement. In these more complex scenarios some data needs to be inserted, while other data needs to be updated. (This seems to be called an Upsert around the Internet)

My initial thought (and of others around me) was to use an OLE DB command on a record-by-record basis to run a custom SQL Stored procedures that was smart enough to insert or update the data as each row is passed to it.

imageAfter some consideration I quickly (in about 10 seconds) realized this did not sound like the best or most performant approach. a Google search on the topic led me to a blog post by Vladimir Gedgafov titled SSIS typical task premier. This post discussed another approach which uses a Lookup Transform as a data-splitter. I do not want to get into all the details of this process yet but it seems like a good strategy on paper: Move all inserts into a Bulk Insert task while keeping updates as a custom-sql execution.

image

In the above example the Lookup splits the source data coming in from the flat file, taking records that have matches and pushing them to update, while all other (so called exceptions) non-matching records get pushed for bulk update.

My goal is to have this working by tomorrow and hopefully post an working example for people in the next few business days. At this stage though this is all theoretical.

Moving SSIS Package Configuration to External Config Files

Today I needed to learn more about making my SSIS packages configurable and found a really great article by Dinesh Asanka. If this topics interests you, definitely check it out.

SSIS Package Configuration in SQL Server 2005

http://www.sql-server-performance.com/articles/dba/package_configuration_2005_p1.aspx

Dinesh Asanka's Blog

http://dineshasanka.spaces.live.com/

(Also with some excellent information on SQL Server, SSIS and Reporting Services)

SSIS: OperationName property does not stick

While in design-time building your SSIS package there a property called OperationName under the FTP Task (FtpTask Class). Unfortunately setting this property, saving and reopening the designer shows this property resetting back to blank. Jamie Thompson was kind enough to help me confirm this bug is not just a local issue on my machine, but seems to be the current (SQL Server 2005 SP2 / Visual Studio 2005 SP1) behavior.

image

The big question you might have is "what the heck is this property?". Its a good question as this property does not seem to be used anywhere.

Here is the official MSDN definition:

FtpTask.OperationName Property

Gets or sets a unique name for the File Transfer Protocol (FTP) task.

Namespace: Microsoft.SqlServer.Dts.Tasks.FtpTask
Assembly: Microsoft.SqlServer.FtpTask (in microsoft.sqlserver.ftptask.dll)

The reason I came across the need to use this property is the FtpTask class. This class does not expose an ID, Name, or Description property to help uniquely identify the instance of the FtpTask, therefore this property seemed perfect, but it does not work.

smile_angry

Let Users Upload Files: A Security Hole

Scott Mitchell wrote an interesting blog post called Another Potential Gotcha When Creating a Website that Allows Users to Share Uploaded Files. This post talks about a security concept that should be almost obvious but yet I must admit, I never thought of it in this way.

While you should read the article for yourself let me summarize the important part: If you let your users upload files and then download them via a URL they can upload script that executes on your server.

Scott posts a solution of turning Execute Permissions for scripts to None. Check out his full article and improve your security profile!

Tuesday, January 15, 2008

Windows Vista Upgrade Advisor Doesn't Like .NET 2.0 (v2.0.50727.42)

The other day a good friend of mine called me with a very odd comment, "Why is .NET 2.0 not compatible with Windows Vista?". I was puzzled, what the heck was he talking about?

As far as I knew .NET 2.0 and up was definitely working on Windows Vista, in fact I have even heard various people using Vista as their development machine using Visual Studio 2005.

My friend though insisted, he told me that a Microsoft application was telling him this, and he could send me a screenshot. Below is that screenshot from Upgrade Advisor that as seen in the last column clearly states "This program might have minor compatibility issues after upgrading to Windows Vista, Click Here to download an update."

screenshot

While the Click Here link in that screenshot might take my friend to a solution, based on his initial reaction it makes me think that the Upgrade Advisor needs to do a better job at communicating issues and their importance to users. (Perhaps simply insisting they run Windows Update to full patch level before this program can correctly analyze their machine)

I tried Googling various variations of words to try and find more information regarding what the compatibilities issues are but have had no luck. Perhaps someone can reply to this post with more details as I am very curious.

SSIS: Errors in parallel activities within a Sequence Container using Transactions

Today while working with a very simple SSIS package I encountered a strange behavior when a failure occurs in a Sequence Container that is created as TransactionRequired.

ssis error

In the above screenshot the FTP Task is failing, and I know it is failing for a valid reason. What I didn't expect is to see the Execute SQL Task fail as well. The error that fails the SQL task is as follows:

[Execute SQL Task] Error: Executing the query "...YOUR SQL QUERY HERE WHICH FAILED..." failed with the following error: "Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

What seems to be happening is an issue of concurrence, or something very similar. My best theory is that the FTP Tasks failure is blowing away the transaction, causing it to be missing for the other parallel task Execute SQL.

To resolve this problem I simply changed the FTP Task to run first, then move control over to the Execute SQL task, as shown in the screenshot below.

ssis error - better

While this was a good solution in my scenario you might have cases when parallel activity is actually required, in which case you should watch for this problem and not assume two tasks are actually failing.

If I am not understanding something correctly I look forward to corrections or comments on this post's feedback thread.

SSIS: Sequence Container with Transaction requires DTC

imageYesterday for the first time since I started working with SSIS I had to group a set of operations in an SSIS package that ran as one transaction. To accomplish this I added a Sequence Container and moved all my tasks into it.

Doing so did not automatically enable the transaction though, to finish enabling this functionality I had to go to the Properties window of the Sequence Container and set the TransactionOption to REQUIRED instead of SUPPORTED which is the default value (See below):

image

Now that everything seemed configured correctly I executed my package which promptly failed at the Sequence level. Since the failure occurred at the Sequence level I knew it was not an issue with my actual tasks an the error message found in the Progress tab supported this theory:

Error: The SSIS Runtime has failed to start the distributed transaction due to error 0x8004D01B "The Transaction Manager is not available.". The DTC transaction failed to start. This could occur because the MSDTC Service is not running.

imageTo resolve the error I simply went to Services MMC and started my Distributed Transaction Coordinator. Anyone who has worked with COM is familiar with this Windows Services, so I knew exactly what to do.

This is a good fact to know that SSIS packages that Require Transactions internally depend on MS DTC (Distributed Transaction Coordinator Services).

image

I also recommend reading Jamie Thompson's post on this topic as it provides additional fundamental information.

Monday, January 14, 2008

SSIS: SQL Server Destination Task Fails... Without Error Detail

image

One very frustrating SSIS experience lately was trying to debug a simple package data flow that ended with a SQL Server Destination Task. The problem was this task showed red after execution but no error pop-up dialog occurred.

To try and figure this out I first looked in Error List tab but found nothing. (No warnings, no errors, no messages)

Next I looked at Progress tab and while it does show some information about Task Data Flow Task failed message along with a few SQL Server Destination line entries (see screenshot below) the exact error detail was still not obvious.

image

Finally it hit me, hovering the cursor over the first line as shown above reveals the following long and detailed error text:

[SQL Server Destination [20]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E2F. An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E2F  Description: "The statement has been terminated.". An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E2F  Description: "Cannot insert the value NULL into column 'COLUMNNAMEHERE - REMOVED', table 'TABLENAMEHERE - REMOVED'; column does not allow nulls. INSERT fails.".

(I removed the column and table name in the error message above to protect the privacy of the system I'm working with)

I was able to view this text while hovering and also use the right-click Copy Message Text feature to move it into notepad for further analysis. After some more digging I also discovered this message exists in the OUTPUT window. Unfortunately the output window is a very cluttered location to look for messages so Progress Tab is still the best places to look first.

Figuring this out killed a good 25 minutes of my life which I will never get back. I hope this post saves you from going through the same.smile_teeth

Friday, January 11, 2008

Object reference not set to an instance of an object. ... A C# story

Today I was writing a small console application and ran into an issue that wasted a good half hour of my time. The console application consisted of one class that I instantiated as MyObject and attempted to run two methods .LoadPackage(), followed by .Execute().

The detailed explanation of the actual object functionality is not necessary but lets talk about what I did inside from a technical perspective:

  • I added a private field of another object, basically saying ABCObject abc = null; I did not want it initialized until the LoadPackage() method was run
  • In the LoadPackage() method I wanted to say abc = new ABCObject(); but instead I wrote ABCObject abc = new ABCObject();
  • Due to this very basic mistake above when I executed .Execute() that tried to do abc.Run() it failed with a "Object reference not set to an instance of an object" error

smile_baringteethLooking back at this I of course realize what happened, by defining the variable again inside of the LoadPackage() function I made it a local variable in the scope of the method, so my field version of abc never got set and the Execute() method always had a null reference. My biggest frustrations with this whole situation are:

  • When setting a breakpoint inside of the LoadPackage() function I didnt see this problem right away since until the method exited the object looked just fine
  • Visual Studio 2005 does not warn me when I override a field in this fashion, perhaps there should be some sort of visual cue?

As my friend from DevBlog would say "this is a classic scope problem" and I know wasting time on this was all my fault, but I definitely feel the tool could be smarter in these kinds of scenarios.

Your thoughts?

Enterprise Library 4.0 Plan Published

The Enterprise Library 4.0 plan has finally been published and a summary of the highlights have been published at the link below:

http://www.pnpguidance.net/Post/EnterpriseLibrary4PlanPublishedCodePlex.aspx

To summarize what is coming even further:

  • Dependency Injection Block
  • Visual Studio 2008 support
  • Various other Misc. Changes

The full list includes 12 major stories and 22 low-priority stories. This list can be found on CodePlex at the link below:

http://www.codeplex.com/entlib/Wiki/View.aspx?title=EntLib4%20Backlog

Properties in C#

Properties are a great way to define public get and/or set variables on your classes. With Visual Studio 2008 improvements have arrived to make working with properties even cleaner.

(If you don't know what properties are then I highly recommend you read Rajesh VS's post on c-sharpcorner for the basics)

Visual Studio 2005

Below is an example of a basic property.

Example:
private string _PackageName = string.Empty;
public string PackageName
{
    get { return _PackageName; }
    set { _PackageName = value; }
}

A nice feature added for .NET 2.0 is the ability to make one of the properties accessors private. For example here I will change the above codes SET accessir to make the setting only possible from inside of the class:

private set { _PackageName = value; }

Visual Studio 2008

In the next release of Visual Studio this is being enhanced even further by allowing something I like to call Short Properties (but the official name is Automatic Properties). This enhancement allows you to skip the body definition if all the code does is the basic SET/GET operation for a value. Here is an example:

Example:

public string PackageName { get; set; };

You can also use the private keyword in the same fashion to limit who can set the property vs. read the property:

public string PackageName { get; private set; };

In my opinion this syntax is much better in the majority of cases as it avoids having to define a private supporting variable and makes for neater and cleaner looking code.

Automatic Properties: C# 3.0 not .NET 3.0

Versions, acronyms, uhh ... confusion.

If anyone else is overloaded with technology like me you probably have suffered at one time or another from a mental block related to reading version numbers. The key to Automatic Properties is that its a C# 3.0 feature, not a .NET 3.0 feature. This is why it is only available with Orcas aka Visual Studio 2008, not as part of the .NET 3.0 extensions for 2005.

Acknowledgments: Special thanks to Jon Skeet for pointing these concepts out to me. I highly recommend everyone check out his new book called C# in Depth coming March 2008. (Click here to view the first chapter for free)

Wednesday, January 9, 2008

SSIS: Hiding Duplicate Columns

image SQL Server Integration Services is overall a very useful ETL tool, but as with any first generation product it has many confusing, annoying or sometimes even disastrous behaviors/feature issues.

One annoying behavior is how the application handles columns as they pass through a Data Conversion Transform. Under existing conditions when you pass in COLUMN1 and COLUMN2 to be converted it will generate COPY OF COLUM1 and COPY OF COLUMN2 (default names that you can change) with the converted data. Unfortunately it will still leave COLUMN1 and COLUMN2 with the original data for the next Transform or Destination box to see and consume.

This gets very annoying when you have a lot of columns being converted and you only care about the new columns being created by the Data Conversion Transform. Sure you can rename the new columns to be easily distinguish but its a poor-mans solution.

Looking around the Internet I found some feedback posted on 1/17/2007 titled: Feedback- SSIS- Hide columns in the pipeline. In this feedback post to the SQL Serve team Jamie Thomson suggests they add exactly this functionality to allow the hiding of columns. Their feedback talks about this being a good suggestion, but that it wont make it into SQL Server 2008 (codenamed: Katmai).

Hopefully this feature can be considered for a future release or service pack of SSIS as it will be a relatively easy change with many benefits to end-users.

Tuesday, January 8, 2008

Keep your computer secure

Keeping a compute secure used to be very difficult and at times expensive. Good software was hard to find  and most of the products cost money that many couldn't afford or didn't want to spend. Recently this has all changed and now many solutions exist to help keep your computer secure.

Even though this is obvious to me I have recently realized that many people are still unaware of the free available options. To help spread the knowledge I have put together the following list that includes just some of the free solutions in this area.

(You can also find more options on Wikipedia's Anti-virus software listing)

Anti-Virus

Product Description
AVG Anti-Virus (Free Edition) AVG anti-virus is a commercial product made by Grisoft. Luckily for people who cant afford anti-virus Grisoft has released a free edition of their anti-virus solution that can scan your machine, monitor your machine in real-time and self-update daily.

I personally use this on many machines and highly recommend it.
Trend Micro: Housecall Housecall is a free web-based anti-virus scanner.

Its web-based nature gives it an advantage in many scenarios since there is no need to install software. This solution instead runs inside of your web browser using Java or a Browser Plug-in.

This is an excellent solution if you don't have a scanner installed and want to inspect your system. I have used to to find and remove viruses on many computers that had no anti-virus before I would download and install a local anti-virus solution.
Norton Security Scan (through Google Pack) Google has somehow struck a deal with Norton to provide a basic version of their anti-virus software through the Google Pack download page.

I have used this before and it seems to install and operate without issue.

Anti-Spyware

Product Description
AVG Anti-Spyware AVG as of recently has started to offer a free version of their Anti-spyware software and while I have never used it before I believe it is worth checking out.
Windows Defender Windows Defender is a free anti-spyware utility made by Microsoft corporation, it works fairly well and the price cant be beat. Being this is a Microsoft product and their recent focus on computer security makes me think this solution will continue to evolve for a long time to come.

Note: In order to download Windows Defender your machine will need to pass genuine copy verification
PC Tools: Spyware Doctor
(Through Google Pack)
Just like with Norton Anti-virus through some deal Google is able to offer Spyware Doctor for free as part of Google Pack.

I have used this product as well and it also seems to work without issue.

Other Security Tips

As you can see from the list above there really is no excuse not to have anti-virus and anti-spyware software on all your computers. Please stay secure as infected computers can hurt you and spread viruses that cost people time and many times pain through data loss.

In closing here are some additional tips to keep your computer secure:

  • Keep your machine updated with all the latest patches by visited Windows Update regularly
  • Keep your Windows XP (sp2) firewall enabled at all times
  • Keep a backup of your data just in case you have an infection that is not prevented or hardware fails
  • Listen to Steve Gibson's TWiT: Security Now podcast as they will really open your eyes to the various threats and issues in this area

Monday, January 7, 2008

My IPhone's New Year Resolution