Thursday, February 5, 2009

SQL CE - NText, doesn't support more than 4000 characters

When using SQL CE and trying to insert data with NText type column that has more than 4000 characters I got this error
Type : System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : @TextContent : String truncation: max=4000, len=27811, value='In the email Content provide the following value,.
When i am looking into this issue, i came to know, that while dealing with NText, we need to add SQLCEParameter like this, to avoid the exception, Changing the command parameters as follows, resolve the issue.
SqlCeParameter textContent;
cmdEmail.Parameters.Add("@ID", ActivityDetails.Email.ID);


cmdEmail.Parameters.Add("@CCRecipients",ActivityDetails.Email.CCRecipients);

textContent = cmdEmail.Parameters.Add("@TextContent", SqlDbType.NText);

textContent.Value = ActivityDetails.Email.TextContent;

cmdEmail.ExecuteNonQuery();

Happy Programming

Wednesday, January 7, 2009

Black Day of Indian Market - Satyam Computers Conspiracy

The Indian stock market today Jan 07,witnessed one of the greatest fall, beacause of the Satyam scam, considered one of the biggest after Harshad Mehta and Ketan Parekh. This new has hammered the stock a lot, which touched a new 52 week low of 30.80, a leap drop of nearly 80%, cornering all those who have bought this share above 150 after Jan 01, to a sleepless night. Yeap, i am the one of those, who have been cornered.

Whom to blame? I thinks there is a consipiracy with the company auditors also, without their knowledge this cannot happen. What's the next step of SEBI, to guard the investors money from going into the hands of these culprits.

God sake, it is important to remember that Satyam doesn't make the entire Indian Software industry, still there are good reputed companies with honest managements in this country, and this scam is not going to represent India as a whole, it just represent a individual.

Hope the Black day for investors as well as the Indian IT industry will pass soon.

Thursday, December 25, 2008

Visual Studio 2008, Intellisense not working after statment completion

Since I upgraded to visual studio 2008, my intellisense stop working. When i complete the statment, i am not getting the intellisense to finish my statement, but if i hit Ctrl + Space, my intellisense was popping up, but that's not enough for me. Everytime i can't hit the keys to get my statement complete. So i just poked into the various option for making things working properly.

When i look into the Tools->Option ->Text Editor->C# (My programming language) - The two checkbox under the statement completion, was unchecked, having checked out the two options, my intellisense starts working.

So, if you have any issues like, intellisense not working, try this approach first.

Happy Programming

Wednesday, December 17, 2008

How to read and create a temporary file from embedded resource



While I was writing the unit test for one of the scenario, where I need to get the data from a csv file from the specified path, for running my unit test. Then comes, the question - How can i add the file to the solution and the get the necessary data from the file and what are the ways? There are two options



  1. First mark the csv file as an embedded resource in the solution, and have a little utility to copy the file to your temp folder and get the path from there.

  2. Mark the csv file as an embedded resource in the solution, and then stream the file straight from the assembly.

The second option is probably preferred because you don't pick up the bottle neck of touching the disk, but unfortunately, my test method accepts the path of the file name, so i have to write a utility to read the file from the assembly, and copy it to the temp folder. Here are the steps to work it out.
To add an file as embedded resource to the project, follow the steps below.
Since the test file will be available with us, just add the file to the project, by choosing Add Existing Item menu in the right click option of the project.



After adding the project, go to the properties of the file added, In the Build Action selection embedded resource, and rebuild the project, that's it your files has been added to the project as an embedded resource.


So now how to read the embedded resource, and create a temporary file.


With the help of assembly.GetMainfestResourceStream(resourceName), you can get the resource stream and the Path.GetTempFileName(), creates a uniquely named, zero byte temporary file on the disk, and returns the full path of that file, and now write the stream to the specified path.



Below is the sample which reads the embedded resource and creates a temp file in the temporary folder.



private const string SampleFile = "TestProject.CRM.ImportData.csv";
public static string UnpackManifestResource(string resourceName, string extenstion, Assembly assemblyName)
{
// Extract the specified resource as a stream
Assembly assembly = assemblyName;
if(assemblyName == null)
assembly = Assembly.GetExecutingAssembly();
string targetPath = Path.GetTempFileName();
if (!string.IsNullOrEmpty(extenstion))
targetPath = Path.ChangeExtension(targetPath, extenstion);
using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
{
if (resourceStream != null)
{
var readBytes = new byte[resourceStream.Length];
resourceStream.Read(readBytes, 0, (int)resourceStream.Length);
using (var outputStream = new FileStream(targetPath, FileMode.Create))
{
outputStream.Write(readBytes, 0, readBytes.Length);
}
}
}
return targetPath;
}

Monday, December 15, 2008

CDO1.2.1 throwing COMException on Outlook 2007

I was working on a Outlook Add-In to save email from Outlook 2003 and 2007 using Outlook Object Modle, which seems to work fine. Then we got a requirement to support the Exchange format mail to, in which we got stucked, while reteriving the email id of the recipients and sender it gives in exchange format, which we doesn't want. To overcome this issue we have used CDO 1.21 to get the SMTP address. This works fine in Outlook 2003, When we are testing it in Outlook 2007, we got an exception, message saying

"Retrieving the COM class factory for component with CLSID {3FA7DEB3-6438-101B-ACC1-00AA00423326} failed due to the following error: ". When i browsed through the net, i came to know that, Beginning in Exchange 2007 Beta 2 and Outlook 2007 Beta 2, CDO 1.2.1 will no longer be provided as a part of the install of the product. As a result, there is functionality missing that many applications depend upon. CDO 1.2.1 is a package providing access to Outlook-compatible objects through a COM-based API.

So if you are using CDO library to access Outlook objects and have plans to move your application to Office 2007. You need to install the CDO 1.2.1 separately. You can dowload the CDO 1.2.1 from here

Happy programming