Pages

Tuesday, October 21, 2014

How to Sync Gmail Contacts With a Smartphone

Step 1
Open your Android device's Settings app. It's typically a grey-and-green gear and is located on your main apps page.
Step 2
Touch the "Accounts & Sync" option to open it.
Step 3
Click the "Add account" button in the lower right corner of the screen.
Step 4
Tap "Google" from the list of account types and click the "Next" button on the screen that comes up.
Step 5
Click the "Sign In" button under the caption saying "Already have a Google Account?"
Step 6
Enter your username and password in the appropriate fields and then click the "Sign In" button in the lower right corner of the screen.
Step 7
Wait for your Android device to communicate with your account.
Step 8
Touch the check box to the right of "Sync contacts" to turn on the check mark and activate contact synchronization. You can also sync Gmail messages, Picasa Web albums and calendar entries by clicking their boxes as well.
Step 9
Press your phone's home button, and the phone syncs your contacts in the background.

Friday, October 17, 2014

SQL Server CLR User Defined Function using Visual Studio 2010

n this post, we will see how to create a User Defined Function using Visual Studio 2010. In my previous article ‘SQL CLR Stored Procedure using Visual Studio 2010’, we have seen how to create a Stored Procedure using C# language with Visual studio 2010. Initial few steps are common for this article like –

1) Enabling CLR using SQL Server Management Studio.
2) Setting connection properties after creating Visual Studio project.
3) Setting security if you are implementing the functionalities like File IO operations or calling Win 32 APIs.

Please follow the steps for enabling CLR under SQL Server as specified in my previous article.

Now let’s create a ‘Visual C# SQL CLR Database Project’ with the name ‘SampleCLRUDF’ as shown below –

SQL Server CLR

Once you create the project, it will ask you for a connection. If you already have created a connection, use the same or create a new connection to the database of your choice. I already have an existing connection to the database ‘SALCLRSampleDB’ database. I will choose the same.

Now let’s add a ‘User Defined Function’ to our project with the name ‘CheckEMailUDF’ as shown below – 

SQL Server UDF

Write some code which will take ‘Email’ address as parameter and will return true or false value depending upon the validation. To do so, first import a namespace ‘using System.Text.RegularExpressions;’ in our function. Now write code to validate the email address as shown below – 

[Microsoft.SqlServer.Server.SqlFunction]
public static bool CheckEMailUDF(string EMailID)
{
   return Regex.IsMatch(EMailID, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}


Now let’s deploy the project. Right click the project and click on ‘Deploy’ menu. Once the deployment is completed, test whether the deployment is successful or not in the ‘Object Explorer’ of SQL Server Management Studio as shown below – 

SSMS Object Explorer

Let’s execute the function and observe the result as shown below – 

USE SQLCLRSampleDB
GO

SELECT dbo.CheckEMailUDF('dabade.pravin')
SELECT dbo.CheckEMailUDF(‘youremailaddresshere@gmail.com')

The result of both select statements is shown below  – 

clip_image001


Reference:
http://www.sqlservercurry.com/2011/05/sql-server-clr-user-defined-function.html

SQL CLR Stored Procedure using Visual Studio 2010

In this post, we will see how to use SQL CLR functionality for defining Stored Procedure using C# in VS 2010. We will also see how to enable CLR under SQL Server.

T-SQL is designed for direct access of data and for manipulation of that data. But T-SQL does not contain arrays, classes, collections, For-Each loop functionalities. However using SQL CLR, we can achieve all of this. With the integration of CLR in SQL Server, we can write managed code to define –
  1. Stored Procedures.
  2. User Defined Functions.
  3. Triggers.
  4. User Defined Type.
  5. User Defined Aggregate.
The decision to use CLR functionality under SQL server needs to be implemented when you are performing –
  1. CPU intensive operations.
  2. Procedures that perform complex logic.
  3. When you want to use BCL (Base class libraries) of .NET framework.
By default the CLR is not enabled under SQL Server. To enable CLR under SQL Server, execute the following command –

SP_CONFIGURE 'clr enabled',1
RECONFIGURE

You will see the following result – 

SQL CLR Enable

Once you enable the CLR, now let’s create a Stored Procedure using Visual Studio 2010 – 

CLR Stored Proc VS 2010

This will display a ‘New Database Reference’ window where we will have to provide a database connection. Let’s set the configuration as shown below –

New Database Reference

If the database is not available, it will get created or you can choose an existing database if you want. After this step, this will ask you whether you want to enable SQL/CLR debugging. Click the ‘YES’ button.

Important Note – Right click your project and go to properties window. Make sure that you have selected the framework - .NET 3.5. Now observe the project under solution explorer. It contains a Test.sql file to test the procedure or function. It also contains PostDeployScript.sql file and PreDeployScript.sql file as shown below –

Post Pre Deploy Script

Post and Pre deployment scripts can be used for modifying, dropping or recreating and taking other actions before or after deployment. Now let’s add a Stored Procedure in our project. Right click the project and add Stored Procedure with the name ‘FileIOOperation’. 

Now import a namespace for the I/O operation – 

using System.IO;

Write code for creating a file and writing a message in the file as shown below – 

File IO Operation

Now let’s deploy the procedure. Right click the project and click ‘Deploy’ from the context menu. Once deployment succeeds, go to SQL Server Management Studio and confirm the deployment. Go to ‘Object Explorer’ > Expand the ‘SQLCLRSampleDB’ > under ‘Programmability’ > ‘Assemblies’ folder you will see our assembly and under ‘Stored Procedures’ folder you will see the stored procedure as shown below –

clip_image001

Let’s try to execute the stored procedure by writing the following code – 

image

If you execute the stored procedure, you will get a security exception as shown below – 

CLR Security Exception

The reason for this exception is this stored procedure will only run under database scope and will not allow you to perform the IO operations. There are three permission sets which are available with CLR objects as explained below – 

1) SAFE – this permission will allow you to perform computation and data access operations within the server. This is the default permission.
2) EXTERNAL_ACCESS – this permission will allow you to access the external resources like files, network, registry, environment variables etc.
3) UNSAFE – this permission will allow you to access restricted resources like WIN 32 APIs.
So for our demo, let’s set the permission to ‘EXTERNAL_ACCESS’. Right click our project and go to properties window. From the properties window, chose ‘Database’ option and set the ‘Permission Level’ to ‘External’ as shown below – 

SQL Permission Level

Now redeploy the project. The deployment will fail because our database is not set to ‘TRUSTWORTHY’ flag. So let’s set the ‘TRUSTWORTHY’ flag to ‘ON’ as shown below –

ALTER DATABASE SQLCLRSampleDB SET TRUSTWORTHY ON

Now again redeploy the project this time the deployment will be successful. 

Now test our stored procedure by executing it. Check on your ‘C:\’ the file is created with the name ‘Test.txt’. Open it and see the message as shown below – 

clip_image004[6]