Sunday, April 29, 2007
Did anyone visit http://www.learnenglish.org.uk/games/magic-gopher-central.swf. If you like simple but excellent tricks visit and enjoy.
If you did play the game visiting the british counsil website, some of you may have picked it up what is happening, but if you didn't then read on.
In this game what they are using is a simple number trick.
It is like this,
You first have to think of a two digit number.
For example we'll take 10,
If you add 1 and 0 then it'll be 1.
Now reduce it from 10 so the result will be 9.
To explain the process i'll take more numbers,
10 -> 1+0=1 -> 10-1 =09
13 -> 1+3=4 -> 13-4 =09
15 -> 1+5=6 -> 15-6 =09
19 -> 1+9=10 -> 19-10 =09
21 -> 2+1=3 -> 21-3 =18
25 -> 2+5=7 -> 25-7 =18
27 -> 2+7=9 -> 27-9 =18
33 -> 3+3=6 -> 33-6 =27
36 -> 3+6=9 -> 36-9 =27
38 -> 3+8=11 -> 38-11 =27
Did any one note anything?
There is always a common number coming for each 10 numbers from 0-9.
00-09 the common number is 0.
10-19 the common number is 9.
20-29 the common number is 18.
30-39 the common number is 27.
40-49 the common number is 36.
50-59 the common number is 45.
60-69 the common number is 54.
70-79 the common number is 63.
80-89 the common number is 72.
90-99 the common number is 81.
In the game what they does is they will put an image for all these numbers in there symbol board. So what ever number we guessed we will end up with one of the above numbers and all the above numbers will have the same image on them. Then the program displays the common image as our symbol saying that it read our mind.
The game ends like that but anyway I think it is better if people had the ability of reading other peoples' minds.
Wednesday, April 25, 2007
Did anyone try sending email using SQL Server?
Ok I tried and got it working, so if you would like to know more please read on. If you face problems while trying this please contact me and I will try helping you sort out the problem.
SQL Server (SQLS) provides Stored Procedure (SP) s which we can use to send mails using SQL. There are two methods in SQL Server 2005.
1.) SQL Mail - SQL Server 2000 provides SQL Mail (The SP you have to use in this method is xp_sendmail.). This method is also supported in SQL Server 2005 (SQLS 2005). But this will not be supported in the next versions of SQL Server. If you are doing a new development the best is to use the Database Mail. Do know that SQL Mail is not supported on 64 Bit versions of SQLS and also remember that SQL Mail is not installed in SQLS 2005 by default.
2.) Database Mail - SQL Server 2005 provides a new method called Database Mail (The SP you have to use in this method is sp_send_dbmail.). This is new to SQL Server 2005 so I will be discussing how to send mails using Database Mail in the following sections of this article using a SP which I wrote as an example. The following SP will read a table and will generate a HTML report according to the data and will send it as an EMail.
Please note that in this article HTML, HEAD, BODY starting and ending tags are proceeded with _ since they are not allowed to be used inside of posts.
--****************************************************************************************
-- Original Developer - Arjuna Chiththananda
-- Description - Sending EMails in SQL Server.
-------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [OWNER].[sp_SendEMail]
(
@ReportDate DATETIME
)
AS
BEGIN
SET NOCOUNT ON;
-- Declaring main variables required.
-- HTMLReport is used to store the report (web page) generated using HTML.
DECLARE @varReferenceNumber VARCHAR(10), @varPassengerName VARCHAR(100), @varDepartment VARCHAR(30), @varTravelInformation VARCHAR(100), @HTMLReport VARCHAR(MAX), @varSubject VARCHAR(75)
-- Starting the creation of web page report.
SET @HTMLReport = '<_html><_head><_title>Ar'
+ '<_body>
SQL Server EMail System
Email Report
'+ '
Report Date -: ' + CONVERT(VARCHAR(15), @ReportDate, 105) + '
'+ '
'
-- Checking a view for data.
IF (SELECT COUNT (*) FROM [OWNER].[vw_ListPassengers] WHERE ReserveDate BETWEEN @ReportDate AND @ReportDate) = 0
BEGIN
SET @HTMLReport = @HTMLReport + 'There are no records to display.'
END
ELSE
BEGIN
-- Creating the table required to format the displayed data.
SET @HTMLReport = @HTMLReport + '
Reference Number | 'Passenger Name | 'Department | 'Travel Information |
' + @varReferenceNumber + ' | '' + @varPassengerName + ' | '' + @varDepartment + ' | '' + @varTravelInformation + ' |
-- Enabling Database Mail.
-- With the default settings Database Mail is not enabled to increase the performance and security of the server.
-- So before using Database Mail we have to enable it on the SQL Server. This is done by setting the configuration option 'Database Mail XPs'. But because is it an advanced configuration option first we have to enable showing advanced options by running the following.
EXEC master.dbo.sp_configure 'show advanced option', '1'
-- To apply the changes run RECONFIGURE.
RECONFIGURE
EXEC master.dbo.sp_configure 'Database Mail XPs', 1
-- On both above options 1 is used to enable the option and 0 is used to disable the option.
RECONFIGURE
-- Now we have enabled Database Mail now we have to start Database Mail.
EXEC msdb.dbo.sysmail_start_sp
-- To send EMails first you have to setup Database Mail. First you have to create an account.
-- I am getting the mail account settings from a table, following are the required variables.
DECLARE @varUserName NVARCHAR(128), @varPassword NVARCHAR(128), @varEMailAddress NVARCHAR(128), @varDisplayName NVARCHAR(128), @varMailServerName NVARCHAR(128), @varPort INT
-- Filling the required variables with the table data.
SELECT TOP 1 @varUserName=EMServerUserName, @varPassword=EMServerPassword, @varEMailAddress=EMSenderAddress, @varDisplayName=EMSenderName, @varMailServerName=EMServerName, @varPort=EMServerPort FROM [OWNER].[tblEMailServer] ORDER BY EMServerOrder, EMServerName
-- Checking whether the account already exists.
-- We can check for existing accounts in the sysmail_account table in the msdb database. As the final section of this article I will list down number of tables which will come in handy while you use Database Mail. (Note my account name is accArjuna.)
IF (SELECT COUNT(*) FROM [msdb].[dbo].[sysmail_account] WHERE [name] = 'accArjuna') = 0
BEGIN
BEGIN TRY
-- If the account does not exist we have to create the account.
EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'accArjuna', -- Account name.
@username = @varUserName, -- Account user name to log in to the SMTP server ('Arjuna'),
@password = @varPassword, -- Password of the above mentioned account ('123').
@description = 'Arjuna Chith on Database Mail.', -- Description of the account.
@email_address = @varEMailAddress, -- EMail address to use to send the mails ('Arjuna@Company.Au').
@display_name = @varDisplayName, -- Name to display in the messages ('Arjuna Chiththananda').
@mailserver_name = @varMailServerName, -- SMTP mail server name ('Server.My.Company').
@port = @varPort -- Port of the mail server if it is diferent from 25 (25 is the default value).
END TRY
BEGIN CATCH
END CATCH
END
-- If the account already exists we will update it, since sometimes the details might have changed.
ELSE
BEGIN
EXECUTE msdb.dbo.sysmail_update_account_sp
@account_name = 'accArjuna', -- Account name.
@username = @varUserName, -- Account name to log in to the SMTP server ('Arjuna'),
@password = @varPassword, -- Password of the above mentioned account ('123').
@description = Arjuna Chith on Database Mail.', -- Description of the account.
@email_address = @varEMailAddress, -- EMail address to use to send the mails ('Arjuna@Company.Au').
@display_name = @varDisplayName, -- Name to display in the messages ('Arjuna Chiththananda').
@mailserver_name = @varMailServerName, -- SMTP mail server name ('Server.My.Company').
@port = @varPort, -- Port of the mai,server if it is diferent to 25 (25 is the default value).
@replyto_address = NULL, -- We can put a reply to address different from above address if we needs to make all replies to the send mail directed to another mail box.
@mailserver_type = 'SMTP', -- Mail server type. Currently only SMTP is supported.
@use_default_credentials = 0, -- Credentials to be used. (1 = SQL Server credentials, 0 = users the username and password given in the above and null = anonymous authentication.)
@enable_ssl = 0 -- If your mail server needs Secure Sockets Layer (SSL) then set it to 1 or make it 0. By making this 1 Database Mail will encrypt communication using SSL.
-- Instead of updating if you want we can delete and add the account again. That part is commented here because you don't need to have both update and delete + add. But if you want you can use this method also.
-- EXECUTE msdb.dbo.sysmail_delete_account_sp
-- @account_name = 'accArjuna' -- When deleting an account we need to give the account id or the name. I prefer giving the name.
-- Now we have deleted the account we will add the modifications as a new account.
-- EXECUTE msdb.dbo.sysmail_add_account_sp
-- @account_name = 'accArjuna', -- Account name.
-- @username = @varUserName, -- Account user name to log in to the SMTP server ('Arjuna'),
-- @password = @varPassword, -- Password of the above mentioned account ('123').
-- @description = 'Arjuna Chith on Database Mail.', -- Description of the account.
-- @email_address = @varEMailAddress, -- EMail address to use to send the mails ('Arjuna@Company.Au).
-- @display_name = @varDisplayName, -- Name to display in the messages ('Arjuna Chiththananda').
-- @mailserver_name = @varMailServerName, -- SMTP mail server name ('Server.My.Company').
-- @port = @varPort -- Port of the mail server if it is diferent from 25 (25 is the default value).
END
-- Now we have to add a Profile.
-- First check whether the profile exists.
IF (SELECT COUNT(*) FROM [msdb].[dbo].[sysmail_profile] WHERE [name] = 'prfArjuna') = 0
BEGIN
BEGIN TRY
-- If not add the profile.
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'prfArjuna', -- Profile name to be used.
@description = 'Arjunas Profile' -- Profile description to be used.
END TRY
BEGIN CATCH
END CATCH
END
-- Now we have added an account and a profile we need to merge both these that is done here after checking whether it exists.
IF (SELECT COUNT(*) FROM [msdb].[dbo].[sysmail_profileaccount] WHERE [profile_id] IN (SELECT [profile_id] FROM [msdb].[dbo].[sysmail_profile] WHERE [name] = 'prfArjuna') AND [account_id] IN (SELECT [account_id] FROM [msdb].[dbo].[sysmail_account] WHERE [name] = 'accArjuna')) = 0
BEGIN
BEGIN TRY
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'prfArjuna', -- Profile to be linked.
@account_name = 'accArjuna', -- Account to be linked.
@sequence_number = 1 -- Determines the order of account usage if you have more than one account. If the first account fails it will try sending mails with the second one in the order.
END TRY
BEGIN CATCH
END CATCH
END
-- Grants the Database Mail profile access to the msdb public database role and to make the profile the default Database Mail profile.
BEGIN TRY
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'prfArjuna', -- Profile name to set.
@principal_name = 'public', -- Makes this profile a public profile.
@is_default = 1 -- Makes the profile the default profile for the principal.
END TRY
BEGIN CATCH
END CATCH
-- Fire RECONFIGURE to make the changes apply to SQL Server.
RECONFIGURE
-- The variable to hold the recipient list of our mail.
DECLARE @varRecipients VARCHAR(MAX)
-- Filling recipient list from the table (Note here I am getting the first one in the table (Which will be the last entry added).)
SELECT TOP 1 @varRecipients=EMailAddress FROM [OWNER].[tblEMail] WHERE EMailActive=1 ORDER BY EMailId DESC
-- Setting the subject of the EMail.
SET @varSubject = 'EMailing in SQL Server on ' + CONVERT(VARCHAR(15), @ReportDate, 105) + '.'
-- We have done the hard part so we will now send our mail.
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'prfArjuna', -- Profile name to be used when sending mail.
@recipients = @varRecipients, -- Recipients who will get our mail. ('Arjuna@Company.Au).
@subject = @varSubject, -- Adding the subject to the mail.
@body_format = 'HTML', -- Format of the mail, this could be Text or HTML.
@body = @HTMLReport -- Message body of the mail.
-- If you want to mail an output of a query you can give your query as follows.
--@query='SELECT RefId FROM FlightBooking.SE.Vw_Report_ListPassengers'
END
--****************************************************************************************
Now we have finished the SP remember to run this sp under a sysadmin or serveradmin role to make sure the reconfigurations will take effect.
When we do Database Mail related things like creating accounts, profiles etc everything will be stored in the msdb. If you would like to query out the statuses, following tables might be helpful.
-- Lists down all the created mail accounts.
SELECT * FROM [msdb].[dbo].[sysmail_account]
-- Lists down all the attachments sent using Database Mail.
SELECT * FROM [msdb].[dbo].[sysmail_attachments]
-- Lists down all the created attachments using Database Mail.
SELECT * FROM [msdb].[dbo].[sysmail_attachments_transfer]
-- Lists down the configuration settings of Database Mail.
SELECT * FROM [msdb].[dbo].[sysmail_configuration]
-- Lists down all the created mail servers.
SELECT * FROM [msdb].[dbo].[sysmail_server]
-- Lists down the activity log of Database Mail, if any error occurs a log entry will be created.
SELECT * FROM [msdb].[dbo].[sysmail_log]
-- Lists down the mails sent from Database Mail.
SELECT * FROM [msdb].[dbo].[sysmail_mailitems]
-- Lists down the principal accounts configured.
SELECT * FROM [msdb].[dbo].[sysmail_principalprofile]
-- Lists down all the created profiles.
SELECT * FROM [msdb].[dbo].[sysmail_profile]
-- Lists down all the created profile accounts.
SELECT * FROM [msdb].[dbo].[sysmail_profileaccount]
-- Lists down the details of results that were returned from the queries that were run using Database Mail.
SELECT * FROM [msdb].[dbo].[sysmail_query_transfer]
-- Lists down the details of retry attempts made.
SELECT * FROM [msdb].[dbo].[sysmail_send_retries]
-- Lists down all the created mail servers.
SELECT * FROM [msdb].[dbo].[sysmail_server]
-- Lists down the mail server type (SMTP) and some settings.
SELECT * FROM [msdb].[dbo].[sysmail_servertype]
Thursday, April 12, 2007
Getting Date part only from SQL DateTime Value
Even though I have taken date part only from a datetime field earlier I had to struggle for some minutes yesterday, so I thought why I shouldn't put a blog entry on this so it will help me. Also I think that this will help many of you reading my blogs.
I found two ways to accomplish this without using DATEPART. I believe it is not good practice to use DATEPART and assemble the date by ourselves because it will sometimes change the original year, month and day order and at times that will cause some unnecessary problems.
Method 1
SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)
What is happening here is CAST(GETDATE() AS FLOAT) will cast the date into a floating point number {2007-04-12 22:12:00.837 = 39182.9236936343}.
Then the FLOOR function will return the largest integer part of the parameter. In our case the result of CAST(GETDATE() AS FLOAT) {39182.9236936343}. The result of this will be 39182.
Now I will caste this value again to a DATETIME value. This time, since there is no fraction part in the value that results in the time part to return as 00:00:00.000. {Fraction part represents the time.}
The final result will be 2007-04-12 00:00:00.000.
Method 2
SELECT CONVERT(NVARCHAR(20), GETDATE(), 101)
In this second approach what I am doing is simply Converting the date into a character. The last parameter of the CONVERT function {101} is the style number which will specify the conversion. Value 101 will return the value in the format of MM/DD/YYYY. {To acquire more information about conversion styles refer CONVERT function in SQL Books Online.} The result of this will be 04/12/2007.
One thing to remember when using second method is that the result will be in the format MM/DD/YYYY. So if you are comparing this value with another date you have to be careful to make the other comparing value also in the format of MM/DD/YYYY. Otherwise it will return wrong results.
Saturday, March 17, 2007
I flashed the ROM of my Pocket PC to version 1.01.03 from 1.00.03. I highly recommend you to upgrade your PPC ROM to the new version since this upgrade will solve many problems that this device is having with the earlier ROM. In the upgrade process I got in to problems initially but at the end I managed to succeed. So I thought of putting a post so that others can do it in one shot unlike me.
You can download the ROM upgrade from
http://h18007.www1.hp.com/support/files/handheldiPAQ/us/download/23981.html
the main software and driver page at HP is
http://h18007.www1.hp.com/support/files/handheldiPAQ/us/locate/1129_6331.html?jumpid=reg_R1002_USEN#0.
As the first thing what you needs to do is backup the data in you PPC because upgrading ROM will erase all the data. The easiest way to save your personal data is to create a ActiveSync membership and sync all the data to a Personal Computer. Then when you complete the upgrade you can sync back and restore the data.
Next make sure that you have ActiveSync 2.0, If you have newer version of ActiveSync I recommend you to uninstal that and install ActiveSync 2.0. You can get it from http://www.microsoft.com/downloads/details.aspx?familyid=7269173A-28BF-4CAC-A682-58D3233EFB4C&displaylang=en.
You should make sure that your computer will not go to standby or hibernate modes and also that your connection from PPC to the computer will be intact while the ROM upgrade is happening. Power failure or cable detach could cost you your PPC.
Remember to remove any SD cards, secondary batteries, SIM cards that you have in your PPC. Also note that it is good practice to charge your PPC above 75% before starting the upgrade.
Next double click on the file you downloaded from HP. Make sure you extract it to the default location provided (C:\iPAQ\SP34074).
Automatically it will start the upgrade process. Follow it as you follow a normal wizard.
If you are lucky the process will continue to 100% and the PPC will reset and will start as usual.
Then create a new partnership with ActiveSync and synchronize the data back to your PPC.
The upgrade process is installing things as follows,
0% - 90% - Pocket PC 2005 and related components
90% - 93% - New Boot Loader
94% - 95% - WAP Component
95% - 100% - WAN Component
If your update process stops at 90% and give a Windows error don't panic. What happens here is that the updater fails while closing the Pocket PC 2005 and opening Boot Loader.
If his happens make sure that you are running ActiveSync 4.2 then disconnect the PPC from the cable and remove the battery for about one minute. At the same time shutdown your computer and restart. Then reconnect the battery. The PPC will then come to a white screen with HP logo on it. now connect the USB cable again.
Go to the place where unzipped the files (C:\iPAQ\SP34074). Double click on hpRUU.exe to manually start the updater again. As you are in trouble already do not start any other applications while the updater is doing its work. If you have followed exactly what I have mentioned this time it should upgrade the ROM successfully. If not what you can do is try another two three times and if this fails you have to send your PPC to a HP service center to upgrade the ROM for you. Or else if you like to continue with the old ROM version you can install the older ROM which can be downloaded from http://h18007.www1.hp.com/support/files/handheldiPAQ/us/download/23966.html.
All the best for your upgrade.
Friday, March 02, 2007
Recently I faced a problem in one of my Tablet PC projects because of an unexpected behaviour of Infragistics UltraFlowLayoutManager.
My scenario is as follows, I am adding dynamically (run time) some UltraExpandableGroupBox controls to a panel which is managed by a UltraFlowLayoutManager. The problem was after the initial display the last group box added to the panel is going missing or appearing in some other location instead of the required location. You can notice this even if the Panel changes its size, normally the layout manger should automatically arrange the controls but here it will not do on the last control added.The actual problem was that the coordinates for the last control was not appropriately set and also the Z order of the control is reduced making it go behind the other controls.
I tried to set the coordinates myself but always the layout manager will override them.
I also tried changing Z order by calling each controls’ BringToFront method. But then all controls will start wondering around.
So as the solution I had to add a dummy Panel control as the last control and I made it to appear as a line to stop confusing users.
Now my application will display a line a the end at times and at times it will not. Kind of AI behavior huh :-).
Saturday, February 24, 2007
I came again to Australia last week. This time I came through Singapore. The airport and it's facilities are wonderful. For the first time in my life I flew in Cathay Pacific and Quantas. Mmm I think even though the Airlines are cutting facilities these days these two airlines are in the list with other airlines who are not going down in their service. But Cathay Pacific are having things which needs to be corrected fast.
Friday, February 09, 2007
Check out the newest member of Microsoft Office product line. Microsoft Office Groove 2007. Groove is a team collaboration tool which will facilitate information sharing. This is what Microsoft is saying about Groove.
Microsoft® Office Groove® 2007 is Internet software for making direct connections with the people who are important to you. With Office Groove 2007, you can bring together team members from both inside and outside your company, with no IT assistance required and no need to waste time thinking about firewalls, servers, security, or network access. Additionally, you can enjoy the efficiency of always knowing each other's virtual location, or online presence, thus allowing for organic and quick conversation and collaboration.
If you are interested in knowing more visit http://office.microsoft.com/en-us/groove/HA101672641033.aspx. There you will be able to find an introduction animation from which you will be able to get an idea of Groove.
Infragistics have released a beta control set which is to be used for WPF (,.NET 3.0) named NetAdvantage for WPF. I think there they have created some cool control set which we'll be able to use with our development. If you are interested find more information at http://www.infragistics.com/hot/wpf.aspx#NetAdvantageforWPFBeta .
Thursday, February 08, 2007
Recently I did face a problem when I created the setup for my Pocket PC application. My application had several projects and each project is supposed to add a dll to the setup. The problem was when I build the project it didn't add the reference dlls to the setup but only added the main application.
Later I found the solution for this which was to remove the main project output from the deployment project then go to debug mode and add the main project back again to the deployment project. The when the project is rebuilt all the dlls will be included properly.
Wednesday, February 07, 2007
Did you ever searched how to use a single quote inside SQL query? In this article I explain how to do.
( 1.) To display a quote in between of two field values.
SELECT FirstName + ''' ' + LastName From tblStudent
The above will put a single quote and a space in between FirstName and LastName fields.
( 2.) To insert a record with a quote to a table.
INSERT INTO [tbl] (ColumnName) VALUES ('I'+'''m ok.')
The above will insert a record into tbl and will put the string of {I'm ok.} to the column ColumnName.
( 3.) To update a record will be possible as follows.
UPDATE [tbl] SET ColumnName='I'+'''m ok.'
The above will update ColumnName values of all the records of tbl in to {I'm ok.}.
Tuesday, January 30, 2007
Have anyone of you installed Windows XP on a machine which is having Windows 2003. If you have, you may have noted that after Windows XP installation Windows 2003 stops booting up. If you do try to start Windows 2003 in safe mode it will stop at CRCDisk.SYS.
The reason behind this is that when Windows XP installs it will replace some of the required common files with Windows XP version. When Windows 2003 tries to start it will fail since it cannot find the required files.
To start Windows 2003 again you have to replace 'NTDETECT.COM' and 'ntldr' on the boot drive (C:). These two files are located in the Windows 2003 CD inside I386 folder.
If this does not start Windows 2003 try running Windows 2003 setup again up until the first restart. When the system restarts Windows 2003 should start as normal.
In the worst case if that also wont solve your problem then you have to repair your Windows 2003 installation by continuing Windows 2003 setup and selecting Repair mode.
Thursday, January 25, 2007
Creating a folder named Prn
Do you know that you cannot create a folder named Prn in Microsoft Windows operating systems?
It is true that you cannot create folder as such visually (Using Windows Explorer). Instead you can create the folder by using command prompt.
Just open the command prompt and type
mkdir file://.c:/prn to create a folder named con in the C drive.
If you need to remove the created folder, type
rd file:////C:/prn
So if you only needed to create a folder named prn this is it, but if you would like to know further read on.
This restriction is because printer is referred by prn in device level (Printer is considered as a virtual folder.). So if you are permitted to create a folder named prn Windows will get confused when it is told to print a document since there are two folders/devices.
What we do here is we are making the directory a network associated folder by using '\\.\'.
Prn is not the only word which is blocked by Windows. Following words are also blocked because they are also representing some device in device level as I have mentioned below.
Word - Represented Device
prn - Printer
con - Console
lpt1 to lpt9 - Parallel Port Interfaces on IBM PCs (Named because at that time this port is heavily used by Line Printers)
com1 to com9 - Communication Ports
aux - Serial Ports
nul - Null (Not 100% sure)
If you need to create folders with the above names you have to create them as network associated folders.
-
If you are wondering a way to change the column header appearing in the .Net GridView control in run time then this post will help you to ge...
-
Last week I spent few hours to figure out why Samsung Galaxy S2 was not connecting to Samsung Kies through USB cable. I could browse phone c...