Tuesday, November 30, 2010

Sql Server–Execute Permissions

One way to provide users execute permissions on a database: (works in Sql Server 2005 and above)
Create a role and grant it execute permissions. Then add your user to that role.
/* CREATE A NEW ROLE */
CREATE ROLE db_executor

/* GRANT EXECUTE TO THE ROLE */
GRANT EXECUTE TO db_executor

Monday, November 29, 2010

Samsung Focus–Diagnostics commands

via: http://forum.xda-developers.com/wiki/index.php?title=Samsung_Focus

Samsung Focus Diagnostic Mode To access the diagnostic program you will need to dial ##634# from the phone pad.
Diagnostic Commands:

  • *#0*# - LCD Test
  • *#0002*28346# - Audio control utility.
  • *#0011# - Power and Temperature and Network Connection monitoring
  • *#0228# - Battery Information
  • *#0289# - Melody Test\Test External and Internal Speaker
  • *#03# - SMDInfo
  • *#05# - Simple test menu
  • *#06# - Show IMEI #
  • *#0673# - MP3 Test Menu\Shows Audio sound tests
  • *#0782# - Shows Clock & Alarms settings
  • *#0842# - Vibrate test menu
  • *#0987# - Multitouch test
  • *#1111# - Show FTA software version
  • *#1234# - Shows the PDA and the Phone version number
  • *#197328640# - The Root Menu
  • *#2*# - Battery Information
  • *#2222# - Show FTA hardware version
  • *#2263# - RAT Selection option is restricted
  • *#232337# - Bluetooth MAC Address
  • *#2580# - Integrity Control
  • *#3*# - Test Brightness
  • *#32489# - (GSM test) Shows the ciphering status and options to enable or disable it.
  • *#7284# - USB Path control
  • *#745# - Operation (2): Ril log done
  • *#7450# - Operation (99):Error Report off done
  • *#7451# - Operation (99):Error Report off done
  • *#7465625# - Shows status of the Network Service Provider SIM or Corporation lock
  • *#770# - Operation (99):Vphone 770 done!
  • *#771# - Operation (99):Vphone 771 done!
  • *#772# - Operation (99):Vphone 772 done!
  • *#773# - Operation (99):Vphone 773 done!
  • *#774# - Operation (99):Vphone 774 done!
  • *#775# - Operation (99):Vphone 775 done!
  • *#776# - Operation (99):Vphone 776 done!
  • *#777# - Operation (99):Vphone 777 done!
  • *#778# - Operation (99):Vphone 778 done!
  • *#779# - Operation (99):Vphone 779 done!
  • *#780# - Operation (99):SR Test done!
  • *#9090# - Diag Config\UART/USB settings
  • *2767*3855# - Full Reset (Caution every stored data will be deleted.)

Tethering Currently instructions only apply to AT&T network, USA.

  • Open the phone screen composition
  • Enter the code: # # 634 # > Press Call<br.
  • This will open a new screen will be similar but in test mode
  • Then type in the code * # 7284 # > Press Call
  • See the screen that you see in the picture > Select Tethered
  • The phone will restart
  • Attach the USB cable to your phone and PC and wait for it to install drivers
  • You will see the phone modem and you can configure the data connection
  • number: *99***1#
  • user name: WAP@CINGULARGPRS.COM
  • password: CINGULAR1

WP7, Samsung Focus and Tethering

Only available via the diagnostics menu:

Dial ##634#. This will open the diagnostics screen.

Dial *#7284#. This will open the tethering configuration dialog.

Select the option “Modem, tethered call”. The phone will take you through a set of steps to configure tethering and will restart the phone. Voila! tethering is now enabled.

Danger: You run the risk of bricking your phone, getting crazy bills from your carrier, etc. So do the above at your own risk.

Sunday, November 28, 2010

Fear and Risk

If you arent scared then you arent taking a risk

for a nation to remain true to its ideals….

For if this Nation is to remain true to the ideals symbolized by its flag, it must not wield the tools of tyrants even to resist an assault by the forces of tyranny.

Justice John Paul Stevens.

Saturday, November 27, 2010

Determining theme on WP7

Knowing which theme has been selected by the user for their WP7 device is important especially if you are using images or colors that work well for one theme and not another. In this case you will have to change the colors/images depending on the currently selected theme.

Here is the simplest way to determine whether the currently selected theme is “Light” or “Dark”

public static bool LightThemeEnabled
{
get
{
return (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible;
}
}

The property returns true if the currently selected theme is the light theme and false if the selected theme is the dark theme.

Incidentally, this is one of the easiest reasons for your app to get rejected during certification for the Market Place. So remember to check all your screens under both the Light and Dark themes.

Jailbreaking comes to WP7

Its called ChevronWp7 and you can read more about it at: http://www.istartedsomething.com/20101126/chevronwp7-windows-phone-7-unlocker-released/

Friday, November 26, 2010

WP7 – Screen Capture on Device

One of the biggest features that I miss as a developer/blogger on the Windows Phone 7 device is the ability to take a screen shot.

The saving grace is that it is extremely easy to add code to your app so as to be able to capture the screen and save it to your album. Once the image has been saved, you can upload it to SkyDrive or to your computer via a Sync operation. (This is better than storing it to isolated storage, as that makes it harder to get at the image).

Here is the code:

using System.Windows.Media.Imaging;
using Microsoft.Advertising.Mobile.UI;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Media;
using System.IO;

public static class Utility
{
/// <summary>
/// Currently supported only on the device. (Does not do anything while running with the emulator)
/// Will throw an exception if called while the device is connected to the computer (tethered mode)
/// so dont do that!
/// </summary>
/// <param name="page">the page whose screen shot needs to be captured</param>
/// <param name="saveName">the name that the image should be saved under - the device seems to ignore this parameter
/// and hence its ok to call this method with the same name multiple times, each image is stored separately</param>
/// <param name="quality">the jpeg image quality parameter</param>
/// <returns>A picture object representing the image</returns>
public static Picture DoCapture(this PhoneApplicationPage page, string saveName, int quality)
{
//first save to bitmap
WriteableBitmap bmp = new WriteableBitmap((int)page.ActualWidth, (int)page.ActualHeight);
bmp.Render(page, null);
bmp.Invalidate();

//get memoryStream from bitmap and save to media library
Picture picture = null;
using (MemoryStream memoryStream = new MemoryStream())
{
bmp.SaveJpeg(memoryStream, bmp.PixelWidth, bmp.PixelHeight, 0, quality);
MediaLibrary mediaTest = new MediaLibrary();

memoryStream.Seek(0, SeekOrigin.Begin);
//name cannot be empty or null
//by default image gets saved to the album "Saved Pictures"
//SavePicture will throw an exception if called while the device is tethered
picture = mediaTest.SavePicture(saveName, memoryStream);
}
return picture;
}
}

And here is one method to call it from one of your application’s pages:

private void ApplicationBarCaptureButton_Click(object sender, EventArgs e)
{
try
{
Picture picture = this.DoCapture("Stocks 50-200.jpg",95);
MessageBox.Show("Screen capture saved: " + picture.Album + " " + picture.Name, "Screen Captured",
MessageBoxButton.OK);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, "Error saving screen", MessageBoxButton.OK);
throw;
}
}

Something to notice is that as DoCapture was defined as an extension method, I am able to call it using the following syntax: this.DoCapture.

And here is what a saved screen-shot looks like (taken from my WP7 App – Stocks 50-200):

69

Thursday, November 25, 2010

Sunday, November 21, 2010

Cool Windows Phone 7 Features via Windows Live

No paying a $100 for a “MobileMe” service. The following awesome features come standard with your Windows Phone 7.

The images say everything:

Map it: see your phone’s approximate location

image

Ring it: Ring your phone, even if its on silent or vibrate mode!

image

Lock it: Lock your phone and even put a “please return” note on it.

image

Erase it: Erase all your personal information remotely.

image

Do more at WindowsPhone.Live.Com

Resetting your iPhone and preparing it for resale

If you plan on selling your iPhone or reselling it, then you should reset it, so as to clear it of all your personal information.

The quick and easy way to do this, is to connect it to iTunes and then using the restore function. (You will be prompted for backing up your phone, but as you plan on not using it – you can just answer no).

image

In addition, the under the Settings application on the iPhone, there is an option for resetting the phone. I am not sure if it is needed – but just to be on the safe side, I reset the device’s settings and content.

Saturday, November 20, 2010

Wp7 App: Stocks 50-200: more information

Read all about the Stocks 50-200 application that should soon hit the Windows Phone 7 marketplace at: http://www.stocks50200.com/2010/11/stocks-50-200.html

http://www.stocks50200.com/

WP7–AdControl–Remote connection to the device has been lost

I was playing with the Windows Phone 7 AdControl and I could not get it working.

I kept getting the following error:

“The remote connection to the device has been lost.  Please verify the device connection and restart debugging.”
image

After hours of debugging I found out the reason I was getting this error was because I had customized the “WMAppManifest.xml” file and had commented out the networking and web-browser component usage capabilities for my test app, as I thought I didn’t need them. Once I uncommented those lines, voila! the adControl began working.

So if you get the above error make sure you are specifying the following capabilities for your application:

<Capability Name="ID_CAP_NETWORKING" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />

Another thing to take a look at are the AdUnitId and ApplicationId values that you are using while initializing the control.

Stocks 50/200…. Coming Soon

Coming soon at http://www.stocks50200.com/

StartupScreen

Wednesday, November 17, 2010

Sql Server– A function to create a temp-table from a delimited string

Here is a SqlServer user defined function that takes as input a delimiter separated string and the delimiter and returns a table.

CREATE FUNCTION [dbo].[StringToTable]
(   
    @inString varchar(8000),
    @delimiter varchar(30)
)
returns @tempTable table (keyvalue varchar(50))
AS
begin
    declare @item varchar(50)
   
    -- remove leading comma
    if substring(@inString,1,1) = @delimiter
        begin
            set @inString = substring(@inString,2,len(@inString))
        end

    -- put in the comma if not there
    if substring(@inString, len(@inString),1) != @delimiter
        begin
            set @inString = @inString + @delimiter
        end

    -- go through and put all the strings in the table
    while charindex(@delimiter,@inString) > 0
        begin
            set @item = substring(@inString,1,charindex@delimiter,@inString)-1)
            insert @tempTable (keyvalue) values (@item)
            set @inString = substring(@inString,charindex@delimiter,@inString)+1, len(@inString))
        end

return

end

Using the StringToTable method:

select * from StringToTable ('Hello,World', ',')

returns:

keyvalue
Hello
World

Wednesday, November 10, 2010

Creating mock DataTable and DataRow objects

For the purpose of testing….
DataRow cannot be instantiated directly as its constructor is protected.
First create the DataTable with the columns you want it to have and then call DataTable.NewRow(). (This just returns a new DataRow object with the schema as specified in DataTable, to add it to the DataTable call DataTable.Rows.Add().


    DataTable table = new DataTable();
    table.Columns.Add("Column1", typeof(int));
    table.Columns.Add("Column2", typeof(string));
    table.Columns.Add("Column3", typeof(string));
    table.Columns.Add("Column4", typeof(DateTime));
    DataRow dataRow = table.NewRow();
    dataRow["Column1"] = 1;
    dataRow["Column2"] = "1";
    dataRow["Column3"] = "1";
    dataRow["Column4"] = DateTime.Now;
    table.Rows.Add(dataRow);






Sql Server–Refresh Intellisense Symbols

To refresh the intellisense list that Sql Server Management Studio displays when typing queries, uses the “Refresh Local Cache” command in the Edit –> Intellisense menu.

image

Saturday, November 06, 2010

.Net–The difference between IEnumerable and IEnumerator

The easiest way to think about these 2 interfaces:

An object that is enumerable will provide an enumerator that allows you to enumerate over that object – Kapish?!

The interface IEnumerable defines one method: GetEnumerator that returns an object that implements IEnumerator. IEnumerator defines methods such as Current, MoveNext and Reset. Typically an object that implements IEnumerable, does so because it contains a list of data-items. Calling GetEnumerator on that object then provides us with an object that manages the iteration over the list of items contained on that object.

In terms of the “Gang of Four” patterns, IEnumerable and IEnumerator implement the iterator pattern and IEnumerable is the Aggregate and IEnumerator is the Iterator.

Sql Server–Performing updates in batches

If you have a table with millions of rows and you want to update one of its columns, one problem that you can run into is that the update causes the log file to grow to such an extent that you run out of space.

One work-around to this problem with the log file growing very large is to update the table in small batches. (Especially when you use Simple logging, this can lead to the log file not growing by much at all).

Here is how I did it:

1. Added a column called Updated to the table. (This column is used to keep track of if the row was updated or not. Based on your tables structure you may or may not need to do this). This column will be deleted at the end of the script.

2. Update the table using top(1000) option.

3. Delete the column used to keep track of whether the row was updated or not.

ALTER TABLE [dbo].[sample]
ADD [updated] BIT NULL;

while (1 = 1)
begin
	Begin Transaction;
	UPDATE top (1000) [dbo].[sample]
		SET [mySampleData] = newValue,
		[updated] = 1
	FROM   [dbo].[sample]
	WHERE [updated] is null;

	if (@@RowCount = 0)
		break;
	Commit Transaction;
end
Commit Transaction;
go
ALTER TABLE [dbo].[sample] DROP COLUMN [updated]
go