Monday, December 13, 2010

Get Time difference using C#

DateTime startTime, endTime;

startTime = Convert.ToDateTime("2:30 AM");

endTime = Convert.ToDateTime("3:30 AM");

var timeDiff = new TimeSpan(endTime.Ticks - startTime.Ticks);

MessageBox.Show("Time difference in hours is " + timeDiff.Hours);

SSIS: Column cannot convert between unicode and non-unicode string data types

Scenario
If you try to import Excel data into SQL Server you may get this error having to convert the columns from Unicode to non-Unicode.

Solution

Use the Data Conversion Task
So to get around this problem we have to also use a Data Conversion task. This will allow us to convert data types so we can get the import completed. Map the non-unicode columns with unicode version of the columns and import the data to SQL server.

Saturday, December 11, 2010

SSIS: Foreach File Enumerator in Foreach Loop Container with dynamic folder path using variables

Setting the folder path in foreach loop container dynamically using a variable.

This can be done by setting the Directory property of the Foreach File Enumerator.

1. Create two variables named @FolderPath and @FileName.

2. Drag a Foreach Loop Container task to the Control Flow panel, double click it to pop up the property window.

3. Switch to the Collection tab, choose the Enumerator as "Foreach File Enumerator", expand Expressions and add two properties "Directory" for folder path and "FileSpec" for filtering specific types of files. Specify "@[User::FolderPath]" to Directory and "*.txt" to FileSpec.

4. Switch to the Variable Mappings and specify User::FileName mapping to the index 0.

Monday, December 06, 2010

Sunday, December 05, 2010

NET4 Client Profile vs NET4 Full Framework?

NET4 Client Profile:
Always target NET4 Client Profile for all your client desktop applications (including Windows Forms and WPF apps).

NET4 Full framework:
Target NET4 Full only if the features or assemblies that your app need are not included in the Client Profile. This includes:

If you are building Server apps. Such as:
  • ASP.Net apps
  • Server-side ASMX based web services

If you use legacy client scenarios. Such as:
  • Use System.Data.OracleClient.dll which is deprecated in NET4 and not included in the Client Profile.
  • Use legacy Windows Workflow Foundation 3.0 or 3.5 (WF3.0 , WF3.5)

If you targeting developer scenarios and need tool such as MSBuild or need access to design assemblies such as System.Design.dll

Projects that target NET4 Client Profile by default

The following projects starting with VS 2010 target the NET4 Client Profile by default:

Windows Project (C# and VB)
- WPF Application
- WPF Browser Application
- WPF Custom Control Library
- WPF User Control Library
- Windows Forms Application
- Windows Forms Control Library
- Console Application
- Empty Project
- Window Service

Visual F#
- F# Application
- F# Tutorial

Workflow (C# & VB)
- Activity Designer Library
- Activity Library
- Workflow Console Application

WCF (C# & VB)
- WCF Service Library

Office 2007 & 2010 templates (C# & VB)
- All Projects

All other projects, including Class Library, target the Full Framework by default.

SSIS Ouput Column Names for errors

The "Error Description" custom component for SSIS (SQL Server Integration Services 2005 and 2008) helps to enhance the error flows.

It provides error description, column name and other useful information.
You can connect many inputs to this component to create effective error flows quickly.

The component is available on Codeplex

http://eod.codeplex.com/

Normally SSIS provides only error code and error column where error column provides only the Lineage Id not the actual column name. The above component does the mapping between Lineage ID and Output Column ID and provides the Column name.

Friday, December 03, 2010

ORA-12154: TNS:could not resolve service name with .NET Windows Services

When I try to connect to oracle database from a .NET Windows service I get the following error.

ORA-12154: TNS:could not resolve service name

a) Tried fixing the NTFS permissions on the oracle folder for the user account running the service.

b) Checked the tnsnames.ora and sqlnet.ora is available and service name is configured in it.

Still I got the same error. If I try to connect to the oracle database from the same server using .NET Windows Forms or Console application, the connection established successfully.

Solution

Change the connection string to expand out the tns entry:

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.161.50.101)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MOUAT)));Password=password;User Id=username;

This will give the real error:

And got 'ORA-06413: Connection not open.'

Which was due to the 'Windows Service' path having brackets in it.

Change the connection string to exclude the TNS resolution and then make sure that the path to the calling application does not contain brackets '(' or ')'.

Thursday, December 02, 2010

Unable to load DLL 'OraOps9.dll'

System.DllNotFoundException: Unable to load DLL 'OraOps9.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Possible reasons for the above error would be using ODP.NET (Oracle Data Provider for .NET) in your application.

Make sure the ODAC (Oracle Data Access Components) is installed on the target machine running the application.

http://www.oracle.com/technetwork/database/windows/downloads/index-101290.html

Wednesday, December 01, 2010

PDF freezing while loading

This happens with pdfs that were published with the fast webview option. (linearized) and having StaticFileHandler mapped to PDF files in the web.config file.

This issue occurs due to a problem with the StaticFileHandler while processing Ranged requests that have a buffer size greater than 16. The default range buffer size is 16. The Adobe PDF web browser plug-in uses Ranged HTTP requests and may send more than 16 ranged fragments for large .pdf files. In this scenario, the StaticFileHandler attempts to resize its buffer by calling the Buffer.BlockCopy function, which results in the web browser hanging and the download failing.

Solution

Remove the StaticFileHandler mapping from the web.config file so that the PDFs can be served via the DefaultHttpHandler.

Tuesday, November 30, 2010

An error occurred while extracting the result into a variable of type (DBTYPE_I4)

This is an obvious error related to output parameter when using "Execute SQL Task" Control Flow item.

Change the parameter mappings from LONG to VARCHAR to fix this error.

How to get ErrorDescription in SSIS

If you use an Error Output in SSIS you will get the ErrorColumn and ErrorCode and not the Error Description. You can get the ErrorDescription by using a script component.

Make sure you a column to the Output that is going to contain the Error Description and use the following code.

VB.NET
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Row.ErrorDescription = ComponentMetaData.GetErrorDescription(Row.ErrorCode)
End Sub

C#

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Row.ErrorDescription = ComponentMetaData.GetErrorDescription(Row.ErrorCode);
}

Saturday, November 13, 2010

Screen Capture on MAC

Use the Command-Shift-3 shortcut for taking a screen capture of your entire screen

Use the Command-Shift-4, which gives a crosshair cursor so you can choose which area of the screen you want to capture.

Use the Control-Command-Shift-3 (or 4), which, instead of creating a file on the desktop, copies the capture into the Clipboard memory,

How can I launch multiple instances of MonoDevelop on the Mac?

On Mac, if you have an app open and you try to launch it again, the Mac just switches to the open app. You can force it to open a new instance by passing the option "-n" to the launcher. In a terminal, run

open -n /Applications/MonoDevelop.app

Note: MonoDevelop is capable of opening multiple solutions. To do this, simply uncheck the "close current dialog" checkbox in the "Open" dialog, or hold down the control key when clicking on one of the recently opened projects in the Welcome Page.

Friday, November 12, 2010

Delete a variable in SSIS Package

To delete a variable from a package

1.In Business Intelligence Development Studio, open the Integration Services project that contains the package you want.

2.In Solution Explorer, right-click the package to open it.

3.On the SSIS menu, click Variables. You can optionally display the Variables window by mapping the View.Variables command to a key combination of your choosing on the Keyboard page of the Options dialog box.

4.In the Variables window, click Show User Variables.

5.Select the variable to delete, and then click Delete Variable.

6.If the Confirm Deletion of Variables dialog box opens, click Yes to confirm.

7.To save the updated package, click Save Selected Items on the File menu.

Wednesday, November 10, 2010

How to raise Error event in SSIS?

Syntax

ComponentMetaData.FireInformation(int InformationCode,
string SubComponent,
string Description,
string HelpFile,
int HelpContext,
out bool pbFireAgain
)

FireCustomEvent
Raises a user-defined custom event in the package.

FireError
Informs the package of an error condition.

FireInformation
Provides information to the user.

FireProgress
Informs the package of the progress of the component.

FireWarning
Informs the package that the component is in a state that warrants user notification, but is not an error condition.

e.g.

bool pbFireAgain = false;

ComponentMetaData.FireInformation(0, string.Empty, "Information", string.Empty, 0, ref pbFireAgain)

Check for file existence in SSIS

How do you check to see if a file does not exist in SQL Server Integration Services (SSIS)?

Use script component and add the following script.

If System.IO.File.Exists("\\Server\Share\Folder\File.Ext") Then
Dts.TaskResult = Dts.Results.Success
Else
Dts.TaskResult = Dts.Results.Failure
End If

The File System Task in SSIS can be used to move, copy, delete files and folders but does not support file existence checks.

Friday, October 08, 2010

How to Add onLoad JavaScript event in SharePoint?

Scenario
If you a have some javascript code that needs to be executed on the onLoad event of a page in SharePoint.

Solution
SharePoint provides a JavaScript array "_spBodyOnLoadFunctionNames", any function to be executed onLoad needs to be added to this array e.g.

Monday, September 20, 2010

Important: ASP.NET Security Vulnerability

ASP.Net uses encryption to hide sensitive data and protect it from tampering by the client. However, a vulnerability in the ASP.Net encryption implementation can allow an attacker to decrypt and tamper with this data.

But what can the attacker do with this capability? Part of the answer depends on the ASP.Net application being attacked. For example, if the ASP.Net application stores sensitive information, such as passwords or database connection strings, in the ViewState object this data could be compromised. The ViewState object is encrypted and sent to the client in a hidden form variable, so it is a possible target of this attack.

If the ASP.Net application is using ASP.Net 3.5 SP1 or above, the attacker could use this encryption vulnerability to request the contents of an arbitrary file within the ASP.Net application. The public disclosure demonstrated using this technique to retrieve the contents of web.config. Any file in the ASP.Net application which the worker process has access to will be returned to the attacker.

Workaround

The workaround for this vulnerability is to use the customErrors feature of ASP.NET to configure applications to return the same error page regardless of the error encountered on the server.

By following the steps in the advisory to map all error messages to a single error page, you make it difficult for the attacker to distinguish between the different types of errors, effectively limiting access to the oracle.

Monday, August 16, 2010

Ajax second postback not working in Sharepoint in UpdatePanel

Scenario

I had an update panel within the Sharepoint where the trigger is set to PostBackTrigger. Any button within the update panel triggered the click event only the first time. After that the click event never got fired until the whole page is refreshed.

This scenario was working in our test environment but doesn't work in our client's test environment. The difference is somewhere with the sharepoint setup.

Solution

Windows SharePoint Services JavaScript has a "form onSubmit wrapper" which is used to override the default form action. This work is put in place to ensure that certain types of URLs, which may contain double byte characters, will fully work across most postback and asynchronous callback scenarios. However, if your scenarios do not involve double byte character URLs, you may successful disable this workaround and gain the ability to use ASP.NET AJAX UpdatePanels.

To do this, you may need to register a client startup script which disables this workaround, in addition to resetting the default form action:

Sunday, August 15, 2010

DataTips in VS2010

While debugging we can mouse over on an variable to look at the value or to explore further and we call this as DataTip. In Visual Studio 2010, we can stick DataTips to our code window and drag & drop to any location and the DataTip will hang there. This really facilitates the debugging process.

Run your application in debug mode and mouse over on the variable to pin and click the pin icon. To unpin, just click the unpin icon again in the debug mode.

Google maps - Part 6 - How to get driving directions?

The driving directions can be calculated directions using the DirectionsService object. This object communicates with the Google Maps API Directions Service which receives direction requests and returns computed results. The results can be displayed using the DirectionsRenderer object to render these results.

Saturday, August 14, 2010

Response.RedirectPermanent

Scenario
Consider that you have created a page named "offers.aspx" which has some item listings and free offers to users when they buy the items.

After the offer has expired you want redirect all the web traffic from "offers.aspx" to "listings.aspx".

If you use Response.Redirect("listings.aspx") in the offers.aspx then it returns a HTTP 302 status to the browser meaning that the "Resource is temporarily moved to another location". This 302 status informs the search engines that the offers.aspx page is temporarily moved. If it returns the same status whenever the search engine crawls, it will ignore the URL for duplicate content.

Solution
To avoid this problem and to improve Search Engine Optimization (SEO) .NET 4.0 has got a new method for performing redirections.

Response.RedirectPermanent("listings.aspx")

This will return a HTTP 301 status "Moved Permanently" to the browser. Because of that the search engine when it crawls the next time will update its URL list.

Alternatively the same can be achieved with .NET 3.5 as mentioned below.

Response.Status = "301 Moved Permanently";
Response.RedirectLocation = "listings.aspx";

Monday, August 09, 2010

Error occured in deployment step 'retract solution' cannot start service SPUserCodeV4 on this computer

I got this error when I tried to deploy a WebPart created using VS 2010 and Sharepoint 2010.

Solution

1. Go to Central Administration

2. Open "System Settings"

3. Open "Manage services on server"

4. Locate the service "Microsoft SharePoint Foundation Sandboxed Code Service"

5. Start the service "Microsoft SharePoint Foundation Sandboxed Code Service"

Now try deploying the WebPart and it will deploy successfully.

Sunday, August 08, 2010

Named arguments and Optional Parameters

Optional parameters - the ability to define a function parameter with a default value. When the function is called, the caller can pass the parameter value if not the default value is used.

Named arguments - C# now provides an ability to name the argument and pass the value along with that in a function call.

VB.NET had it for a while. This will be useful when you code with COM API's.



Note: Optional parameters must be specified at the end (after defining the required parameters)

System.Dynamic - ExpandoObject in C# 4.0

The ExpandoObject enables to create new members for an object in runtime. The ExpandoObject was introduced in C# version 4.0.

Note: You must reference System.Dynamic.dll to use ExpandoObject.

Friday, August 06, 2010

Google maps - Part 5 - How to create info windows?

Info windows are really a good way of showing important information about a particular location indicated by a marker. These info windows can display text or can have any HTML inside it.

Tuesday, August 03, 2010

Google maps - Part 4 - How to clear markers on google map?

I had an interesting scenario where I had to clear the markers on a google map. It was quite easy to do in Google Maps API v2. But in API v3 it is not straight forward.

Whenever you create new markers you need to push them into an array. When you need to clear the markers just loop through the array with the markers and remove them.

Monday, August 02, 2010

Google maps - Part 3 - How to create a marker on google maps?

Markers are indicators on google map to denote the places of interest. This post will explain you how to place a marker on google map.

The marker object resides in the google.maps.Marker namespace and takes a single argument, options. Options is an object literal called Marker options that can have several properties of which two are required:

map [Map]
Map is a reference to the map where you want to add the marker.

position [LatLng]
This property indicates the position of the marker and is of type google.maps.LatLng

How to copy a DLL from the GAC

I was trying to copy the System.Web.Extensions dll from the GAC to my application bin folder. You can do that using the following command.

solution
copy "C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\1.0.61025.0__31bf3856ad364e35" C:\temp\project\bin

Sunday, August 01, 2010

How to escape XML text in c#?

Escaping XML text is basically encoding the following symbols (<, >, &, ", ').

This can be done in the following ways.

a) Using Replace function

string xmlData = "I live in \"wellington\" & I love listening to music."
string escapedXmlData = xmlData.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "&apos;");

Note: Replace the & symbol first.

b) Using System.Security.SecurityElement.Escape() method

string xmlData = "I live in \"wellington\" & I love listening to music."

string escapeXmlData = System.Security.SecurityElement.Escape(xmlData);

Thursday, July 29, 2010

Google maps - Part 2 - How to get current lat, lng and zoom level

Once a google map is initialized and when it is re-positioned, the latitude, longitude and zoom level can be determined using the following example.

Monday, July 26, 2010

Google maps API v3 - Part 1 - How to create a simple map?

Recently I worked on a project using Google maps. It was originally developed using Google maps API v2. I changed it to use v3 API.

Google maps v2 vs v3 API

Version 2 API requires you to register for an API key for every domain that uses google maps and must be inserted into the QueryString for the script reference. Version 3 API doesn't require an API key.

How to create a simple map?

1. First thing is to add the following script reference to your HTML page.


Note: sensor attribute is to specify whether your device has a sensor or not. (just to determine the user's location.

2. Create an object with the latitude and longitude co-ordinates. Simple map with NZ co-ordinates.

Sunday, July 18, 2010

DateTime MinValue in SQL SERVER and C#

I was trying to store C# DateTime.MinValue in SQL SERVER and got the following exception

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

In SQL Server the minimum date that can be stored in a datetime field (1753/1/1), is not equal to the MinValue of the DateTime .NET data type (0001/1/1).

Therefore if your datetime value is DateTime.MinValue then don't save it in SQL SERVER.

Tuesday, July 13, 2010

IIS6 Meta bas compatibility in IIS7.5 and windows 7

IIS7 has done away with the metabase, but some pre-IIS 7 applications rely on the metabase as part of their installation process. This is a Windows feature that you can turn on and off throught the control panel.

Note: This is not a separate install.


Monday, July 05, 2010

IIS 7.5 and Windows 7

HTTP Error 500.19 - Internal Server Error

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

Solution

The applicationHost.config had the handler section locked:

Changed


to


and it fixed the issue.

System.Data.SqlClient.SqlException: New transaction is not allowed because there are other threads running in the session.

I got this error when using Entity Framework with the following code.


Solution

The foreach loops were the culprits. I needed to call EF but return it into an IList of that target type then loop on the IList.

Yahoo Style Guide

The style guide for the Internet age

Anyone can publish on the Web, but not everyone is publishing material that's ideal for online reading. Enter "The Yahoo! Style Guide," your guide to writing and editing for the Web. People read online text differently, and they have different expectations when they read it -- most notably, they expect instant gratification, the ability to find what they want on a webpage fast

The Yahoo! Style Guide: The Ultimate Sourcebook for Writing, Editing, and Creating Content for the Digital World" will be in stores from July 6

Check the site for more information.

Tuesday, June 29, 2010

IIS Express

Microsoft have been working on a new flavor of IIS 7.x that is optimized for developer scenarios that we are calling “IIS Express”. It combines the ease of use of the ASP.NET Web Server with the full power of IIS. Specifically:

  • It’s lightweight and easy to install (less than 10Mb download and a super quick install)
  • It does not require an administrator account to run/debug applications from Visual Studio
  • It enables a full web-server feature set – including SSL, URL Rewrite, Media Support, and all other IIS 7.x modules
  • It supports and enables the same extensibility model and web.config file settings that IIS 7.x support
  • It can be installed side-by-side with the full IIS web server as well as the ASP.NET Development Server (they do not conflict at all)
  • It works on Windows XP and higher operating systems – giving you a full IIS 7.x developer feature-set on all OS platforms


IIS Express (like the ASP.NET Development Server) can be quickly launched to run a site from a directory on disk.

Look at scott Guthrie's post for more information.

Note: Beta will be released soon.

Linq

I am using Linq to entities in one of my project and here are the few things I found.

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

You may get the above error if you try to use the ToString() method in your Linq to SQL or lambda expression. To fix this try storing the ToString() value in a temporary variable and pass the temporary variable to the lambda query.

A specified Include path is not valid. The EntityType 'xxxxxxx' does not declare a navigation property with the name 'xxxxxxxx'

You may get the above error if you try to use a wrong entity name with Include.

eg. entities.Category.Include.Where(cat => cat.CategoryId == 1)

Friday, June 18, 2010

First project

Time for some real work after all other initial stuff in my new work place. I have started working on a project which has a mix of technologies Sharepoint, ASP.NET, C#, Linq to Entities, WCF, ASMX Web services, SQL SERVER 2008.

I am working on an Import/Export task using C#, Linq to Entities, WCF, ASMX Web Services.

I know about the Linq to Sql Debugger Visualizer addin for Visual Studio and it looks like Linq to Entitites also have one similar to that.

Linq to Entities Debugger Visualizer

Monday, June 14, 2010

Free icons to use for Applications Development

FAMFAMFAM Icons - http://famfamfam.com/lab/icons/silk/

http://p.yusukekamiyamane.com/

http://jonasraskdesign.com/iconarchive/iconarchive.html

Linquify

Business Class Generator for LINQ to SQL and the Entity Framework

Linquify by Primary Objects is a C# .NET business class generator for LINQ to SQL and the Entity Framework, helping to support rapid development of .NET and ASP .NET web application data layers. Linquify is free for use under the LGPL.

Linquify installs as a Visual Studio 2008/2010 addin, which allows you to select your LINQ to SQL dbml file or Entity Framework edmx file and automatically generate a set of easy to use business classes. The generated classes allow you to support a complete 3-tier software architecture and simple handling of database objects, with full support for LINQ queries. Customizations to the generated classes can be easily made within the generated user partial classes.

Linquify Key Features

  • Visual Studio 2008/2010 Addin for easy generation.

  • Compatible with LINQ to SQL and the Entity Framework.

  • Compatible with SQL Server, MySQL, Oracle, and any other compatible database platform via the LINQ provider, DbLinq.

  • Automatic generation of Types library, containing business classes, and supporting 3-tier architecture.

  • Simple Load(), Save(), Delete() methods for making database calls.

  • Full support for LINQ queries.

  • Full support for passing DTO objects within Session and between postbacks.

  • Optimized SQL query execution.

  • Includes generated partial classes for customizing business objects.


Download Linquify Addin v 1.6

Note: The above installer should automatically create VS2008/2010 addin. If it is not created you can create it manually using the following instructions.

Linquify Addin instructions - Manual install

Wednesday, May 26, 2010

ELMAH

ELMAH - Error Logging Modules and Handlers can be plugged into any Web based ASP.NET application for application wide logging. It's an awesome open source project. To read more about how to configure ELMAH - http://dotnetslackers.com/articles/aspnet/errorloggingmodulesandhandlers.aspx

How to configure ELMAH on IIS6 for SQL SERVER

  1. Download the ELMAH binaries from http://code.google.com/p/elmah/downloads/list

  2. Copy the ELMAH.dll to your application's bin folder.

  3. Add the following to the web.config file


  4. Run the DDL script from this URL on your database to create the necessary table and stored procedures.
  5. Now navigate to http://yourwebsiteurl/elmah.axd

Monday, May 24, 2010

Concatenate multiple rows into one string using SQL

I needed to concatenate the multiple rows of a query into a string. I could have used a function to do the same but I need to do that via SQL on a ORACLE database.

Solution


Note: This has got a limit of 4000 characters. Good to use in subqueries where you are trying to concatenate less no. of rows. SYS_CONNECT_BY_PATH is only available in Oracle 9i version or later. For earlier versions you need to write a function to do the same.

Thursday, May 20, 2010

SQL SERVER 2008 R2 Express upgrade failing

I was trying to upgrade my SQL SERVER 2008 Express with Advanced Series instance to SQL SERVER 2008 R2 Express with Advanced Series.

The upgrade was failing with the upgrade rules especially with SQL SERVER 2005 tools. Note: I had SQL SERVER 2005 installed in the same Virtual PC

To upgrade to SQL SERVER 2008 R2 Express make sure to remove the SQL SERVER 2005 tools via Add/Remove programs. Probably it won't appear in the same name instead you need to remove SQL SERVER 2005 but chose the Workstation components to uninstall and not the Database engine.

Once removing it try the upgrade and it will work successfully.

SSIS Terminologies

SSIS - SQL SERVER Integration Services (since SQL SERVER 2005) previously named as DTS - Data Transformation Services

SSIS is an ETL application - Extraction Transformation Load
BIDS is the Development tool - Business Intelligence Development Studio
Package - Product that SSIS produces
Control flow - Workflow of a package
Data flow - Movement of data in a package
Task - Individual Unit of Work
Transform - Individual Unit of Work in a data flow
Event Handler - Handle errors, warnings or events.

Run Exe's in Windows 2008 Task Scheduler

I had a requirement where I needed to run a program as a scheduled task. I configured the program but it wasn't firing the exe at all. At last I figured out that I cannot execute an EXE via Task Scheduler and used a batch script to wrap the EXE call and scheduled it in Task Scheduler.

@echo off
echo %date% %time% Start of task > c:\temp\test.log
echo User=%UserName%, Path=%path% >> c:\temp\test.log
c:\Tools\Task.exe 1>>c:\temp\test.log 2> c:\temp\test.err
echo ErrorLevel of c:\Tools\YourTask.exe=%ErrorLevel% >> c:\temp\test.log
echo %date% %time% End of task >> c:\temp\test.log

How to get a range of rows in SQL SERVER and Oracle?

I had a request where I need to get a specific set of rows with a start row number and end row number and I needed to have the Query for both SQL Server and ORACLE.

Solution

SQL SERVER


ORACLE

AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts

If you are using Dynamic data controls and if you get the following error?

Microsoft JScript runtime error: AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the AjaxScriptManager in System.Web.Ajax.dll, or use the ToolkitScriptManager in AjaxControlToolkit.dll.

Solution

Are you using ScriptManager or ToolkitScript manager? You need to use the ToolkitScriptManager in order for the new AJAX Toolkit to work.

Change
<asp:ScriptManager ID="ScriptManager1" runat="server" />

to

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>

SSIS: Connect to Oracle database

I've been trying to access data in Oracle from SSIS via OLE DB and was getting the following warning:

"Cannot retrieve the column code page info from the OLE DB Provider. If the component supports the "DefaultCodePage" property, the code page from that property will be used. Change the value of the property if the current string code page values are incorrect. If the component does not support the property, the code page from the component's locale ID will be used."

Solution
Set AlwaysUseDefaultCodePage=TRUE on the OLE DB Source component that shows the warning and it will work fine

Monday, April 26, 2010

Chemistry for Word Addin

Chem4Word addin makes it easier for students, chemists and researchers to insert and modify chemical information, such as labels, formulas and 2-D depictions, from within Microsoft Office Word.

Currently this addin is applicable for Word 2007 and above versions.

It uses Chemical Markup Language which is XML for chemistry. Good to see periodic tables appearing in Word documents.

Beta version of the product is currently available at http://chem4word.codeplex.com/

Demo - http://research.microsoft.com/en-us/downloads/3fe31020-0e51-4ee0-ada3-5cd142bcf930/default.aspx

Saturday, April 24, 2010

Visual Studio 2010 and Windows Azure launch

I went for the Visual Studio 2010 and Windows Azure launch yesterday. Visual Studio 2010 as usual has been released with lots of new features.

The Keynote on Windows Azure platform was provided by David Chappell. His presentation was really good and more informative too. I learnt a lot about Windows Azure yesterday.

Check his blog http://www.davidchappell.com/blog/. He has got some good white papers on Windows Azure Platorm and Applications Lifecycle Management (ALM).

Thursday, April 22, 2010

TownHall - Engagement tool from Microsoft

Microsoft has launched a Cloud Computing product "TownHall" that would help Government to engage with the public using social media tools.

TownHall is a cloud based solution hosted on the Windows Azure Platform.

http://www.microsofttownhall.com/

TownHall allows users to post questions, raise concerns and share ideas with other community members, and vote on positions.

Concept looks good but UI is not looking so good.

SQL SERVER 2008 R2

SQL SERVER Express 2008 R2 databases can host databases of size up to 10 GB. Previously until the release SQL SERVER 2008 it was only 4 GB. It will really good for small business customers.

Full features supported by SQL SERVER 2008 R2

http://msdn.microsoft.com/en-us/library/cc645993(v=SQL.105).aspx

http://blogs.technet.com/dataplatforminsider/archive/2010/04/21/sql-server-2008-r2-released-to-manufacturing.aspx

Wednesday, April 21, 2010

Creating a package using SSIS

Currently working on a project to import data from one platform to another using SSIS 2008. This video helped me to get started with SSIS 2008.

The video outlines the basic steps to follow to create a package using SSIS using control flow and data flow.

http://msdn.microsoft.com/en-us/library/cc952921.aspx

Using SSIS on 64 bit plaform but the development tools are available (BIDS) only in 32 bit. So if you need to test the packages using 32 bit in the development and target it to 64 bit environment so that they can be executed on 64 bit platform.

Wednesday, March 17, 2010

Execute permission to all stored procedures

Run the following script and copy the output and execute it again.

Extract text from pdf

PHP function to extract text from PDF

Thursday, February 18, 2010

Ordered Dictionary

I had an issue with loading a dynamically generated DropDownList options via a XML file. Initially I was loading the options for the dropdownlist from the XML file to a Hashtable. But when I tried to display that the order in which the items were displayed wasn't the way it was loaded.

I tried using SortedList to fix the issue but my users insisted that they need the flexibity of maintaining the order via the XML file.

Solution

I changed the SortedList to OrderedDictionary and it solved my problem. The OrderedDictionary retains the order in which the options were inserted. So this solves my customer requirements. From performance wise, it is ok using OrderedDictionary for limited number of options.

Disabling Configuration Inheritance For ASP.NET Child Applications

I had a HttpModule for my parent website and I had a virtual directory under the parent website. When I tried to access the virtual directory, I got the following error.

Could not load file or assembly 'XXXXXXXX' or one of its dependencies. The system cannot find the file specified.

Solution

Include the following in the parent website web.config file to exclude any of the config settings so that the settings doesn't get inherited from the parent website to the child virtual directory.

<location path="." inheritInChildApplications="false">
[any other config settings]
</location>

Tuesday, February 09, 2010

SQL Server Reporting Services Error

The report server cannot decrypt the symmetric key that is used to access sensitive or encrypted data in a report server database. You must either restore a backup key or delete all encrypted content. (rsReportServerDisabled) Get Online Help
Bad Data. (Exception from HRESULT: 0x80090005)

Solution

Possible reasons would be either the account for running the SSRS 2008 has been changed or port number has been changed. To fix the above error,

a) Logon to the Reporting Services Configuration Manager.
b) Make a note of the settings in all the sections.
c) Click the Encryption Keys section.
d) Click the "Delete" button to delete encrypted content.
e) Check whether all the settings in all the sections are intact and also make necessary changes.
f) Click the "Change" button to replace the encrypted content with the updated changes.

Change the timezone info on Search Server Express 2008

The timezone need to be changed in couple of places in Search Server 2008 Express.

a) Application Management > Sharepoint Web Application Management > Web Application General Settings.

b) On the Search Central site, click on Site Actions > Site Settings > Site Administration > Regional Settings.

Friday, February 05, 2010

How to identify SQL SERVER version and edition

Run the following command to find the version and edition of SQL SERVER



or


Check this link (http://support.microsoft.com/kb/321185) to find what service pack has been installed.

Monday, February 01, 2010

Set up a service account to run application pool

a) Give "Logon as a service" and "Logon as a batch job" permissions to the newly created service account.

Note: If you don't give the above permissions, the application pool will crash.

b) Run the following command

aspnet_regiis -ga \AccountName

The above command with -ga switch grants the following rights to the account:
1. Access to the IIS Metabase

2. Permission to write to the %Windir%\Microsoft.NET\Framework\version\Temporary ASP.NET Files folder

Thursday, January 28, 2010

Client cannot connect to remote SQL Server over TCP/IP

a) Make sure Remote connections are enabled on the SQL SERVER instance.
b) Configure your firewall to allow connections through the desired ports.

Default SQL SERVER instance uses port 1433 for TCP/IP

1. Open the Windows Firewall with Advanced Security
2. Right Click on inbound rules and select New Rule
3. Create a Port Rule, Click Next
4. Choose TCP rule and choose ports 1433, 1444. Click Next.
5. Choose Allow the connection. Click Next.
6. Choose the correct profile. By default all of them are on, but you might choose only to let domain machines access SQL... Click Next
7. Specify a Name and a Description for the Inbound Rule. Click Finish
8. Your rule should be created

Now use your client to connect to the Remote SQL SERVER instance and it will work.

Data at the root level is invalid. Line 1, position 1

I got this error "Data at the root level is invalid. Line 1, position 1" when I tried to read an XML file using C#.

Initially I was checking whether the XML is well formed and tried opening in IE to make sure whether it opens fine. IE didn't show any errors and my XML document was fine.

I couldn't figure out what's gone wrong. After a few minutes I realised that I was using XML.LoadXML() instead of XML.Load().

Actually I had my code initially to load an XML string so I was using XML.LoadXML() but changed the logic to load an XML document but forgot to change the code to XML.Load().

XML.Load() - to load an XML File
XML.LoadXML() - to load a XML String

Wednesday, January 27, 2010

Attempted to read or write protected memory

I am getting the following error in the Event Viewer continously.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Services that trigger this error:

Windows Sharepoint Services 3
Office Sharepoint Server

Solution

Install this hotfix to stop the errors.

This fix is for IIS 6 and IIS 7

http://support.microsoft.com/default.aspx?scid=kb;EN-US;946517

Application Server Administration job failed for service instance

I changed the service accounts for the following services which are part of my Search Server 2008 Express installation. The Central Administration and Search Administration websites stopped working after that.

Windows Server 2008 64 bit OS
IIS7

I checked the Event Logs and the following error message was recorded.

"Application Server Administration job failed for service instance"

The above error occurred for the following services.

Windows Sharepoint Services 3
Office Sharepoint Server

I ran the following commands which fixed the above issue and the Central and Search administration pages started working.

1) net stop osearch
2) net start osearch
3) iisreset /noforce

Tuesday, January 26, 2010

AspNetHostingPermission Security Exception Fix in IIS7

I used the ASP.NET Server Control, part of Search Server Community kit in an Intranet site.

The Intranet site was running on IIS 7 and the application pool running on Classic mode. (need to make some changes to run on Integrated pipeline) mode.

Deployed the search page and placed the Microsoft.SearchToolkit.DotNetSearchControls.dll in the bin folder.

Tried loading the search page and got the following error.

System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Solution
Set 'Load User Profile' to true for the application pool and it will fix the above security exception.

Monday, January 25, 2010

Search Server Express 2008 Installation & Configuration

I worked on implementing Search Server Express 2008 for an Intranet Website. The installation process was a bit confusing as I was trying to do a Advanced installation (Web & App server and a separate SQL Server). I tried doing the basic installation on a VM to understand the installation steps and then tried the advanced installation.

Couple of things where I spent time are

a) Configuring crawling of PDF Files.

Since I was installing Search Server Express 2008 on a Windows 2008 64 bit server, I installed the Adobe PDF IFilter 9 for 64 bit platforms [http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025]

Then did the following.

1. Add the filter extension to the file types crawled.

Start > Program > Microsoft Office Server > Sharepoint 3.0 Central Administration > > Search Settings > File Types > New File Type (Add PDF extension)

3. Modify the following Registry keys by changing their "Default" value to the new CLSID of the Adobe IFilter: {E8978DA6-047F-4E3D-9C78-CDBE46041603}

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf
Default --> {E8978DA6-047F-4E3D-9C78-CDBE46041603}

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf

Default --> {E8978DA6-047F-4E3D-9C78-CDBE46041603}

4. Add PDF icon to the PDF extension

1) Copy the .gif file that you want to use to the following folder:

Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Images

NB: Make sure that the gif is 16 x 16 pixels.

2) Open the Docicon.xml file in Notepad. The Docicon.xml file is located in the following folder:

Drive:\Program Files\Common Files\Microsoft Shared\Web server extensions\60\Template\Xml

3) In the [ByExtension] section of the Docicon.xml file, add the following line, where NameofIconFile is the name of the .gif file:

[Mapping Key="pdf" Value="NameofIconFile.gif"/] ... e.g. [Mapping Key="pdf" Value="icpdf16.gif"/] Note: Replace '[' with < and > symbols.

b) Best bets not working

When I do a search for a given term in the Search Center site, the Best Bets come up before the results. But when I do the same search with my customised search page using the Web Service the best bets are not returned.

Solution: Use the URL you used to setup your keywords and best bets for the webservice and it will work. For eg. http://[website name used to setup keywords]/_vti_bin/search.asmx

Please let me know if any one has any issues with the installation of Search Server Express and I am happy to share my experiences.