Sunday, May 24, 2009

Sample to use XML in Stored Procedure

Hi,

Here is a sample to use XML string as a input to a Stored procedure. The stored procedure uses SP sp_xml_preparedocument. Which is capable of reading a XML string. It parses the XML and provides a parsed document which could be used like a temporary table in run time.

Following is the simple code:

1. SQL Script to Create Table:

/****** Object: Table [dbo].[Fund_Index_Relationship] Script Date: 05/24/2009 12:21:20 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Fund_Index_Relationship](

[ID] [int] IDENTITY(1,1) NOT NULL,

[Fund_ID] [int] NULL,

[FundIndex_ID] [int] NOT NULL,

CONSTRAINT [PK_Fund_Index_Relationship] PRIMARY KEY CLUSTERED

(

[ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

2. Stored Procedure:

-- =============================================

-- Author: Fauzi

-- Create date: 180808

-- Description: TO update Relationship between Fund & Index

-- =============================================

CREATE PROCEDURE [dbo].[XML_SP_Sample]

@xmlString TEXT,

@Fund_ID int,

@Output VARCHAR(1000) OUTPUT

AS

BEGIN

DECLARE @idoc INT

EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlString

-- Insert Section

INSERT into [Fund_Index_Relationship]

(

Fund_ID,

FundIndex_ID

)

SELECT

Fund_ID,

FundIndex_ID

FROM OPENXML (@idoc, '/Items/Item',1)

WITH (

Fund_ID int './Fund_ID',

FundIndex_ID int './FundIndex_ID'

)

END

3. XML string to Test SP:

[XML_SP_Sample] '<Items><Item><Fund_ID>34</Fund_ID><FundIndex_ID>2</FundIndex_ID></Item><Item><Fund_ID>34</Fund_ID><FundIndex_ID>3</FundIndex_ID></Item><Item><Fund_ID>34</Fund_ID><FundIndex_ID>4</FundIndex_ID></Item><Item><Fund_ID>34</Fund_ID><FundIndex_ID>5</FundIndex_ID></Item></Items>'


Hope it Helps :)


Regards

Fauzi


Friday, May 22, 2009

NVARCHAR vs VARCHAR

When i goggled to find the difference between using NVARCHAR versus VARCHAR, found this neat & simple explanation on the same:

http://weblogs.asp.net/guys/archive/2005/01/15/353550.aspx

How can I Develop a Webpart for MOSS from my XP machine

Hi,

Hope every one will not be getting a chance to work in MOSS server (a windows 2003/2008 Server) simultaniously when working as a team. So when you develop a webpart for a MOSS site from your XP machine, you will not find the assemblies like Microsoft.SharePoint that sharepoint 2007 uses. The solution is you can just add the reference for the following location.

\\MYMOSSSERVER\C$\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

Hope it helps

Regards
Fauzi

Wednesday, May 20, 2009

Difference between Synchronous & Asynchronous Event handlers in MOSS

When i was googling to find the difference between Synchronous & Asynchronous Event handlers in Sharepoint MOSS 2007. I came across the link which was simple & nice.

Link

Regards
Fauzi

Monday, May 18, 2009

New release of the Ajax Control Toolkit

Friends,

New version of Ajax tool kit (May 2009 release) is now available...

Download link

Regards
Fauzi

Wednesday, May 13, 2009

Unable to start debugging on the web server. The web server is not configured correctly...

Hey all:

When you build a web solution in Visual studio, if the following error message is shown:

"Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information."

There can be two reasons...

A) The directory where the web application stays may not be configured as web application.

Steps to Solve:
1. Right click the project folder & Click properties.
2. Select "Web Sharing" tab.
3. Choose the option "Share this folder" radio button & Edit Alias window will pop-up, Press OK and build the application.

B) The Frame work version may not be the appropriate one.
Steps to Solve:
1. Right click the project folder from IIS (Run>inetmgr), Click properties
2. Select ASP.NET tab & select the appropriate ASP.NET Version from combo box.
3. Press OK & build the application again.

Hope it is helpful...

Regards
Fauzi

Tuesday, May 12, 2009

Where is the debugger or host Application Running? - Adobe Flash Player 9


Hi Folks,

Where is the debugger or host Application Running?

I got this message box repeatedly many times when ever a flash component is there in the web page i b
rowse which is annoying for any user...

The solution is we need to just install the patch file which can be downloaded from macromedia site. Following are the links to download...

For Firefox: flashplayer_9_plugin_debug

For IE : flashplayer_9_ax_debug

Hope it helps

Best Regards
Fauzi ~4Z

How to delete all records from all tables from Database

Dear Reader,

Following is the SQL query used to delete all records from all tables from Database.
This is useful during development scenarios where you need to get rid of all the dummy records and insert a fresh data.

SQL Query: Appropriate comments are provided to explain its operation

/* The Following set of queries is used to delete all records from all tables from your database */

/* Disables Referential integrity */

/*---------------------------------*/

EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

GO

/* Delete records from tables */

/*----------------------------*/

EXEC sp_MSForEachTable '

IF OBJECTPROPERTY(object_id(''?''), ''TableHasForeignRef'') = 1

DELETE FROM ?

else

TRUNCATE TABLE ?

'

GO

/* Enables Referential integrity */

/*-------------------------------*/

EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'

GO

/*Query ot be used if you would like to reseed all table*/

/*------------------------------------------------------*/

EXEC sp_MSForEachTable '

IF OBJECTPROPERTY(object_id(''?''), ''TableHasIdentity'') = 1

DBCC CHECKIDENT (''?'', RESEED, 0)

'

GO


Hope its Helpful

Regards
Fauzi

How to get current project path in C#

The Code is to get the current path where the application/project resides...

Syntax: HttpContext.Current.Request.PhysicalApplicationPath

Example: StreamReader(HttpContext.Current.Request.PhysicalApplicationPath + @"\DataBase\Fauzi_db.sql");

Tuesday, May 5, 2009

Read Resource file: Resource.resx dynamically thourgh C#

Dear Reader,


Following is a sample method to read a Resource file in your web application which resides in the location "App_GlobalResources\Resource.resx". The assembly references needed are


using System.Collections;

using System.Resources;


Is case if there is a message shown when solution is built


"The type or namespace name 'ResXResourceReader' does
not exist in the class or namespace 'System.Resources' (are you missing an
assembly reference?)"


Please refer ResXResourceReader missing an assembly reference


Source code:


public void ReadResourceresx()

{

//Creating a hashtable to store string in resource files

Hashtable resourceStringsHashTable = new Hashtable();

//Provide relative path of Resource file

string strResourceFilelocation = HttpContext.Current.Request.PhysicalApplicationPath.ToString() +

@"\App_GlobalResources\Resource.resx";

//Creating object for Class: ResXResourceReader

System.Resources.ResXResourceReader objResXResourceReader = null;

try

{

objResXResourceReader = new ResXResourceReader(strResourceFilelocation);

//Defines a DictonartEntry Key/Value to Set or retriev values

foreach (DictionaryEntry resourceString in objResXResourceReader)

{

if (!resourceStringsHashTable.Contains(resourceString.Key.ToString()))

{

//Adding values to HashTable one by one in a loop

resourceStringsHashTable.Add(resourceString.Key.ToString(), resourceString.Value);

}

}

}

finally

{

//Closing the created object

objResXResourceReader.Close();

}

}

Hope it helps :)

Regards

Fauzi