This blog is subject the DISCLAIMER below.

Saturday, September 12, 2009

Reading POP3 (secure) SSL like Gmail via C#

Friend of mine asked me about reading messages by pop3 protocol using C#code. After I did some search in Google I got a lot of pop agents that working fine but not with Gmail as it uses secure connection (SSL) so I did new search in google and sourceforge but most of them have exceptions or not working fine and this is the main reason for this post to continue work from the point I have stoped.

After a hard search in alot of pages I got two good result :
1- it is a good project (from this blog) have good description that implements the standard POP3 commands like authenticating, receiving stats, retrieving and deleting messages .

2-There are open source project called OpenPOP in sourefourge but have bugs and fixed (here) in this blog by Kiran banda,unfortantualy it have build errors but i fix it (here) but it needs some work to go live.

Related post :
Reading Atom feed of Gmail inbox via C#




.. more.

Friday, September 11, 2009

Reading Atom feed of Gmail inbox via C#



Today I am coming with Gmail feature that may be useful although many people don't know and how to access it via simple C# code.
Gmail Atom feed is xml format file to know the unread messages .

http://mail.google.com/mail/feed/atom/ shows the most recent unread items from your inbox. Gmail also offers feeds for your labels:http://mail.google.com/mail/feed/atom/labelname/ .
To know the feature in detials go to this link @ (the unofficial news and tips about Google).

As a developer you can download the C# example here.
All what you need is create instance a simple class called GmailHandler and drop this lines in your project.


//just 2 steps to get your Gmail Atom
//1- Create the object from GmailHandler class
GmailHandler gmailFeed = new GmailHandler("WriteHereYourGmailUserName(ex: fci-h)", "WriteHereYourGmailPassword(ex: XXX)");
//2-get the feed :) ,Congratulations
XmlDocument myXml = gmailFeed.GetGmailAtom();


Just happy code :)

.. more.

Thursday, September 10, 2009

Backup and Restore SQl Server DB by c#

In this post I am going to talk about SQL server DB backup and restore via C#.
lets get into the code.

First thing, you have to reference the following two references

  1. Microsoft.SqlServer.ConnectionInfo
  2. Microsoft.SqlServer.Smo
--------------------------------------------------------------------

1) Create a connection to the SQL Server

private static Server CreateServerConnection(string ServerIP, string SQLInstanceName, string userName, string password)
{
try
{
// Create a new connection to the selected server name
ServerConnection srvConn = new ServerConnection(ServerIP+ @"\" + SQLInstanceName);

// Log in using SQL authentication instead of Windows authentication
srvConn.LoginSecure = false;

// Give the login username
srvConn.Login = userName;

// Give the login password
srvConn.Password = password;

// Create a new SQL Server object using the connection we created
return new Server(srvConn);
}
catch (Exception ex)
{
// Handle Exceptions
}

}
--------------------------------------------------------

2) Perform DB Backup

/// The name of the .bak file
/// SQL Server instance name
/// The name of the Db we want to backup
/// serverIP">IP of the server where the SQL server installed
/// for sql Authentication, example sa
/// Password of the DB user

public static void BackUpDB(string backUpFileName, string SQLInstanceName, string DBName, string serverIP, string userName, string password)
{
try
{
Backup bDatabase = new Backup();

// Set the backup type to a database backup
bDatabase.Action = BackupActionType.Database;

// Set the database that we want to perform a backup on
bDatabase.Database = DBName;

// Set the backup device to a file
BackupDeviceItem bkDevice = new BackupDeviceItem(backUpFileName, DeviceType.File);

// Add the backup device
bDatabase.Devices.Add(bkDevice);

//Check if the file exists
if (File.Exists(backUpFileName))
File.Delete(backUpFileName);

// Perform the backup
bDatabase.SqlBackup(CreateServerConnection(serverIP, SQLInstanceName, UserName, password));

}
catch (Exception ex)
{
// Handle Exceptions
}
}
-------------------------------------------------------------------

3) Perform DB Restore

/// the .bak file
///
///
///
///
///

public static void RestoreDB(string restoreFileName, string SQLInstanceName, string DBName, string serverIP, string userName, string password)
{
try
{

Restore rDatabase = new Restore();

// Set the restore type to a database restore
rDatabase.Action = RestoreActionType.Database;

// Assign a db to restore operation
rDatabase.Database = DBName;

// Set the backup device to restore from file
BackupDeviceItem bkDevice = new BackupDeviceItem(restoreFileName, DeviceType.File);

// Add the backup device to the restore type
rDatabase.Devices.Add(bkDevice);

// Replace the Db if already exists
rDatabase.ReplaceDatabase = true;

if (File.Exists(restoreFileName))
// restore
rDatabase.SqlRestore(
CreateServerConnection(serverIP, SQLInstanceName, userName, password));
}
catch (Exception ex)
{
// Handle Exceptions
}

}

---------------------------------------------------

That's it

.. more.

Wednesday, September 09, 2009

Want to learn SQL Server Data Services (SDS)?

Overview of Microsoft SQL Server Data Services
This 1-hour online clinic provides SQL Server developers who are experienced in implementing database solutions with an overview of SQL Server Data Services (SSDS).

The topics covered in the clinic include:
- Introduction to SSDS
- SSDS Object Model
- Working with SSDS

More on: http://learning.microsoft.com/Manager/ResourceDetails.aspx?resourceId=cbe836be-394e-4a23-9f87-5d12127cccd5&clang=en-US&brand=Learning

Developing an Application for Microsoft SQL Server Data Services
This 1-hour online clinic provides SQL Server developers who are experienced in implementing database solutions with an explanation of the knowledge and skills required to develop an application in SQL Server Data Services (SSDS).

Topics covered in the clinic include:
- Building an SSDS Application
- Enhancing an SSDS Application

More on: http://learning.microsoft.com/Manager/ResourceDetails.aspx?resourceId=9b2d7204-9f2e-4657-a4c7-0952b32ae081&clang=en-US&brand=Learning

More on SQL Azure Database: http://www.microsoft.com/azure/data.mspx

.. more.