Sunday, December 2, 2012

The breakpoint will not currently be hit in Silverlight project

Solution to the "The breakpoint will not currently be hit" in Silverlight project

Solution 1:
1. Right click on the Silverlight project
2. Locate and click the Web tab
3. Make sure that the Silverlight checkbox is checked.

Solution 2: What if the Silverlight checkbox is already checked, you have already cleaned the solution, deleted the BIN and OBJ folders and still, it doesn't work?
1. Uncheck the Silverlight checkbox
2. Run the solution (the breakpoint will not work, of course!)
3. Stop running. Go the properties again and re-check the Silverlight option.
It works for me!

Solution 3: Clear the browser's cache / temporary files

Solution 4: Usually deleting the <solutionfilename>.suo file in the solution folder fixes it.



Tuesday, November 20, 2012

Telerik Report: RendererNotAvailableException... rendering format is not available

Scenario: I am trying to export the report programmatically
Feature: Telerik Reporting export feature
Error Message: "RendererNotAvailableException... rendering format is not available" for the following formats:

- DOCX
- HTML
- PPTX 
- XPS

Code Snippet: 
Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport(format, reportToExport, deviceInfo);
 reportBytes = result.DocumentBytes;
 if (reportBytes != null && reportBytes.Length > 0)
                Mailer.SendNotifications(_report, reportBytes);

Solution:
As noted in the Deploying Applications using Telerik Reporting help section, the DOCX/PPTX/XLSX rendering extensions require Telerik.Reporting.OpenXmlRendering.dll and Open XML SDK 2.0 for Microsoft Office (DocumentFormat.OpenXml.dll v.2.0.5022.0 or above).

The XPS rendering extension requires Telerik.Reporting.XpsRendering assembly (Telerik.Reporting.XpsRendering.dll). In both cases your project should be targeting .NET 3.5 Framework or above.


If just adding the DocumentFormat.OpenXml.dll does not work, then, the

Open XML SDK 2.0 for Microsoft Office must be installed first on the server.

If still, it doesn't work, check the project that references to the project where Telerik Reporting is originally referenced. That project also needs the mentioned DLLs.

Friday, October 26, 2012

Insert Record(s) to a Table from Another Table



insert into TableDocument2(DocumentId, DeptId, a, b, c, d,e) 
select DocumentId, 9, f, g, h, i, NULL from TableDocument


Wednesday, October 24, 2012

Get the Sum of a Particular DataTable Column

Use the DataTable.Compute method


    DataTable table;
table = dataSet.Tables["Orders"];

// Declare an object variable. 
object sumObject;
sumObject = table.Compute("Sum(Total)", "EmpID = 5");
where "EmpID = 5" is a filter expression. 

Use empty string if filter expression is not needed.

Tuesday, October 23, 2012

Get "2 days before" Dates


Get "2 days before" dates
SELECT * FROM Table1 WHERE DATEDIFF(day, CURRENT_TIMESTAMP, SampleDateField) = 2; 

Another sample usage of DATEDIFF
SELECT DATEDIFF(day, CURRENT_TIMESTAMP, SampleDateField) as 'Days' from Table1

Wednesday, October 10, 2012

Convert PagedCollectionView to Original Source

ObservableCollection<SavedReport> obvColSavedReports = new ObservableCollection<SavedReport>();
                foreach (var savedReport in ((PagedCollectionView)dataGrid1.ItemsSource).SourceCollection)
                {
                    SavedReport sr = (SavedReport)savedReport;
                    if (sr.IsSelected)
                        obvColSavedReports.Add(sr);
                }


See the bold text above? That's it!

Tuesday, October 2, 2012

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.



Problem Summary:
I am getting the above error when I'm trying to import data from excel file in the production server. But, import excel is working on my local machine.

Cause:
The server does not have the proper DLL installed.

Solution:
Install the Office System Driver: Data Connectivity Components in the server.




Tuesday, September 25, 2012

Problem with Different TimeZones

* In progress...

Scenario:

The users are from different timezones e.g. Philippines, India, Redmond WA USA, Florida. A user input a specific schedule to run a task. The task should execute on his/her timezone.

The servers are in the US. SQL Server 2008 and SQL Azure store the user's time. A windows service installed in the server will execute the task. Currently, in the windows service, the scheduled date is being treated with same timezone as the server.

What.to.do?
1. Is there a way in which I can solve this without changing the database schema?
2. In what ways can I check the user's timezone against the server's time? Can the use of UTC solve this?
3. Or do I really need to update the database, add User's TimeZone column to the table for schedules?

Storing times
  • Always store time in UTC
  • Convert to local time on display (local being defined by the user looking at the data)
  • When storing a timezone, you need the name, timestamp and the offset. This is required because governments sometimes change the meanings of their timezones (eg: the US govt changed DST dates), and your application needs to handle things gracefully... eg: The exact timestamp when episodes of LOST showed both before and after DST rules changed.

Possible Solution (Still needs of POC):
1. User to select date and time. Since currently, there is no option for selecting a time zone, automatically get user's timezone, then save in the database as UTC using DateTime.UTCNow (and Date.getTimeZoneOffset()?)

The problem with automatically getting the user's time zone is this scenario, what if the user wants to schedule a task in Philippine time but she is currently in Japan? The user would mentally/manually convert from PH time to JP time and then enter the date and time? 

2. Retrieve the UTC from the database, then convert to user's local time. How? Use TimeZoneInfo.ConvertTimeFromUtc 
http://stackoverflow.com/questions/3439468/utc-to-users-local-time

SOLUTION:
1. DateTime dateNow = DateTime.Now;
   Console.WriteLine("The date and time are {0} UTC.", TimeZoneInfo.ConvertTimeToUtc(dateNow));


2. TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);

Oh men, where should I get the user's current timezone?
Gotcha!
DateTime fromUtcToLocal = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, TimeZoneInfo.Local);
Console.WriteLine("Local Date and Time {0}:", fromUtcToLocal);

References:
The Authority - http://msdn.microsoft.com/en-us/library/bb397769.aspx
Closest to my requirement - http://stackoverflow.com/questions/832986/how-to-work-with-timezone-in-asp-net
Synchronizing Time Zones - http://stackoverflow.com/questions/179940/c-sharp-convert-utc-gmt-time-to-local-time
Links Worthy of Reading:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=593
http://stackoverflow.com/questions/7577389/how-to-elegantly-deal-with-timezones
The Death of DateTime?
http://stackoverflow.com/questions/2532729/daylight-saving-time-and-timezone-best-practices
http://stackoverflow.com/questions/441109/get-datetime-for-another-time-zone-regardless-of-local-time-zone


Bonus:
If I want to list all timezones:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2ddc265b-434a-4c5d-be27-5d6a92e89070/
http://msdn.microsoft.com/en-us/library/bb397781.aspx



Tuesday, September 18, 2012

How to Run/Embed Flash to Silverlight?

It is not possible to run flash content inside of Silverlight or vice-versa. However, it is possible to run both types of content on the same html page. 

For a workaround, an html that is running a flash content can be overlayed to Silverlight. But, the windowless param should be true. (And this option affects the application's performance.) 

What is the flash content? Is it a video? If yes, it can be converted to Silverlight, wmv, avi or any other video formats that Silverlight supports. 

References:
http://stackoverflow.com/questions/618193/can-i-include-flash-content-inside-a-silverlight-app



DOCX rendering format is not available.

This error happens when a Telerik report is to be exported to Word document programmatically.

Take a look if the following DLLs are referenced:
Telerik.Reporting.OpenXmlRendering.dll
DocumentFormat.OpenXml.dll
Telerik.Reporting.XpsRendering.dll (for Xps file)

Note:
If just adding the DocumentFormat.OpenXml.dll does not work, then, the
Open XML SDK 2.0 for Microsoft Office must be installed first on the server.

Reference:
http://www.telerik.com/community/forums/reporting/telerik-reporting/report-export-to-docx.aspx


Monday, September 17, 2012

Silverlight Reporting Solutions: A Quick Comparison

Our Requirement: old Asp.Net solution + Microsoft Reporting to be re-written to Silverlight 5.

Microsoft Reporting is not supported in Silverlight. Hence, a need for displaying the old reports to Silverlight or convert the old reports to Silverlight-compatible reports.

1. Telerik Reporting 
Telerik Reporting provide Silverlight report viewer but their own reporting engine/designer/tool must be used.
Telerik’s report definition can be deserialized from XML. It can cater dynamically created reports.
However, if the client's old reports are created using Microsoft Reporting, these old reports must be converted (migrated) to either Telerik report format.
The only formats in which we can convert Telerik reporting from are crystal, active and xtra reports.

2. DevExpress XtraReports
DevExpress XtraReports is the counterpart of Telerik Reports. I am not sure though if their report is built on XML. Their documentation is not quite good. Same as the Telerik Reports, the old reports must be converted to DevExpress format

One good thing about PerpetuumSoft is that they have Silverlight Viewer for Reporting Services, which displays the reports generated by SSRS directly within Silverlight. However, it’s features are very limited - no serialization support, cannot load dynamic reports, cannot load rdlc files. SSRS is different from Microsoft Reporting.

This provides the foundation in which one can build his own printing and reporting systems in his applications.
This reporting is based on using Silverlight controls to layout the reports. Because of this, the output will be rendered as bitmap, resulting in low print quality and large files being sent to the printer. Being rendered in bitmap, expect very poor performance. The rendering will be too slow.
But since this is custom, one needs to code his own mechanism for pagination, automatic layouting to fit content, manually handle the printing etc.
This is applicable only for simple reports but for complex ones, it can be very difficult and time-consuming!
It has no support for exporting the report to any format. 

My picks:
1. If it's okay to open a new window from Silverlight, then show an Asp.Net page. Then there's no need for conversion. The disadvantage is, it will leave the Silverlight UI and may give an illusion that the user is transferred to another system.

2. Telerik Reporting - well-documented, with serialization support, can cater dynamics, good technical support. The disadvantage - needs conversion so it's time consuming. Write a conversion tool? Microsoft Reporting is totally different to Telerik Reports that's why 'til now, Telerik does not support conversion. Good luck.

How about you? What reporting solution are you using in your Silverlight application?

SQL Azure: Tables without a clustered index are not supported in this version of SQL Server

Msg 40054, Level 16, State 1, Line 3
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.


The MSDN explains that "a table must have a clustered index. If a table is created without a clustered constraint, a clustered index must be created before an insert operation is allowed on the table."


We have been encountering this error after we've migrated to SQL Azure. Sure enough, there is a tool to migrate from SQL Server to SQL Azure, but we have a feature that dynamically creates a table in the database. The task is written in a stored procedure and the script is for SQL Server, so it is not covered by the migration tool. Once the stored procedure is executed (creates a table), it does not automatically add a clustered index, producing the error above when we insert a record in the newly created table.


How do we solve the issue?

First, get all user tables without clustered index

USE ASampleDatabase

SELECT name

FROM sys.objects

WHERE type = 'U'

      AND object_id

            NOT IN (SELECT object_id FROM sys.indexes WHERE index_id = 1)

Example Results:

Table1
Table2

Then, add a clustered index by performing "alter" statement to the tables. Here's the example for Table1:

ALTER TABLE[dbo].Table1
      ADD CONSTRAINT [PK_Table1]
      PRIMARY KEY CLUSTERED
(
    [PrimKey] ASC
)

Of course, we can create a more elegant script to automatically add clustered indexes to those affected tables, but the example above is already enough to get us started.


Stwaf! ^_^

SQL Server Tip: Word Wrap in Sql Server Management Studio

I am having a hard time looking at the complex scripts I have copied from a file to the Sql Server Query Designer. Either I am scrolling all the way to the left or I'm finding (Ctrl + F) and hitting the Enter key when I've found the commas. Then, I remember word wrap! I know, I get silly sometimes.

So how do I set Word Wrap in SQL Server Mangement Studio? By going to the menu,



  • Tools
    • Options
      • Text Editor
        • All Languages
          • Settings 
            • Check Word Wrap

There you go! Simple but helpful!
By the way, I am using version 2008.

Stwaf! ^_^