Monday, June 25, 2012

Joining String


DECLARE @categories varchar(1000)
SET @categories = NULL
SELECT @categories = COALESCE(@categories + ',','') + CONVERT(VARCHAR(20),WIndApplicationID) FROM dbo.WIndApplications
WHERE WIndFormTypeID = 4

PRINT @categories


SELECT ',' + CONVERT(VARCHAR(20),WIndApplicationID)
FROM dbo.WIndApplications
WHERE WIndFormTypeID = 4
FOR XML PATH('')

Tuesday, May 15, 2012

Component with CLSID XXX failed due to the following error: 80070005 Access is denied


Issue:
Component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

[5/11/2012 2:02:45 PM] Error: Excel Extraction Failed :- Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Solution:
1. In DCOMCNFG, right click on the My Computer and select properties.
2. Choose the COM Securities tab
3. In Access Permissions, click "Edit Defaults" and add Network Service to it and give it "Allow local access" permission. Do the same for <Machine_name>\Users.
4. In launch and Activation Permissions, click "Edit Defaults" and add Network Service to it and give it "Local launch" and "Local Activation" permission. Do the same for <Machine_name>\Users


Wednesday, May 9, 2012

Export To PDF

private void ExportToPDF(DataTable pdtblData)
{
byte[] bytFileData = null;
string strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".pdf";
bytFileData = GeneratePDF(pdtblData);
if(bytFileData != null)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytFileData);
Response.End();
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel3, UpdatePanel3.GetType(), "scriptEF", "alert('Error Occured')", true);
}
}

Export To Excel

private void ExportToExcel(DataTable pdtblData)
{
string strFileData = string.Empty;
byte[] bytFileData = null;
string strfname = string.Empty;
strFileData = GetHTMLData(pdtblData);
strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".xls";
bytFileData = Encoding.ASCII.GetBytes(strFileData.ToString());
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytFileData);
Response.End();
}

Export To CSV

private void ExportToCSV(DataTable pdtblData)
{
string strFileData = string.Empty;
byte[] bytFileData = null;
string strfname = string.Empty;
strFileData = GetCSVData(pdtblData);
bytFileData = Encoding.ASCII.GetBytes(strFileData.ToString());
strfname = Services.IDGenerator.GetUniqueKeyWithPrefix(_strPerfix, 10) + ".csv";
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfname);
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(bytFileData);
Response.End();
}