Friday 10 June 2011

Oracle backup and Restore code in c#.net

For Backup:

protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime Time = DateTime.Now;
        int year = Time.Year;
        int month = Time.Month;
        int day = Time.Day;
        int hour = Time.Hour;
        int min = Time.Minute;
        int second = Time.Second;
        int millisecond = Time.Millisecond;

        string path = "C:/oracle/product/10.2.0/backup/";
        path = path + day + "-" + month + "-" + year + "-" + hour + "-" + min + "-" + second + "-" + millisecond;
              
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = "C:/oracle/product/10.2.0/db_1/BIN/exp.exe";
        psi.RedirectStandardInput = false;
        psi.RedirectStandardOutput = true;
        //psi.Arguments = string.Format("USERID=test/test  FULL=y FILE=" + path + ".dmp CONSISTENT=y GRANTS=y BUFFER=100000 rows = Yes");
        psi.Arguments = string.Format("USERID=test/test  FILE=" + path + ".dmp TABLES=(t)");
        psi.UseShellExecute = false;
       
        Process process = Process.Start(psi);
        process.WaitForExit();
        process.Close();
        Response.Write("<script>alert('Database Backup Completed Successfully')</script>");
      
    }
For Restore:

 protected void Button2_Click(object sender, EventArgs e)
    {
       // 2011-4-5-16-5-49-156.dmp
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = "C:/oracle/product/10.2.0/db_1/BIN/imp.exe";
        psi.RedirectStandardInput = false;
        psi.RedirectStandardOutput = true;
        psi.Arguments = string.Format("USERID=test/test  FILE=C:/oracle/product/10.2.0/backup/111.dmp FROMUSER=test TABLES=(t) IGNORE=y");
        //imp SYSTEM/password FULL=y FIlE=dba.dmp
        psi.UseShellExecute = false;


        Process process = Process .Start(psi);
        process.WaitForExit();
        process.Close();
        Response.Write("<script>alert('Database Restore Completed Successfully')</script>");

    }


Monday 23 May 2011

Pre And Post Build Events in C#

http://visualstudiohacks.com/general/customize-your-project-build-process/

http://bytes.com/topic/c-sharp/answers/424841-post-build-events

http://www.dotnetperls.com/post-pre-build-macros


Friday 20 May 2011

SQL Server Date Formats

http://www.sql-server-helper.com/tips/date-formats.aspx

How To Get IP Address Of A Machine

 Getting the Host name and IP Address of Local Machine:
namespace NKUtilities 
{
    using System;
    using System.Net;
    
    public class DNSUtility
    {
        public static int Main (string [] args)
        {
        
          String strHostName = new String ("");
          if (args.Length == 0)
          {
              // Getting Ip address of local machine...

              // First get the host name of local machine.

              strHostName = DNS.GetHostName ();
              Console.WriteLine ("Local Machine's Host Name: " +  strHostName);
          }
          else
          {
              strHostName = args[0];
          }
          
          // Then using host name, get the IP address list..

          IPHostEntry ipEntry = DNS.GetHostByName (strHostName);
          IPAddress [] addr = ipEntry.AddressList;
          
          for (int i = 0; i < addr.Length; i++)
          {
              Console.WriteLine ("IP Address {0}: {1} ", i, addr[i].ToString ());
          }
          return 0;
        }    
     }
}
 
Getting the Local Machine's IP Address: 
 using System;
using System.Net;

class Test {

public static void Main() {
   IPAddress[] a = Dns.GetHostByName(Dns.GetHostName()).AddressList;
   for (int i=0; i<a.Length; i++)
      Console.WriteLine ("IpAddr[{0}]={1}",i,a[i]); }

}
 
For Any Host by using the site address:
using System;
// using the System.Net namespace
using System.Net;
class Class1
{

[STAThread]
static void Main(string[] args)
{
// Request the name
Console.Write("Please type the name of the host: ");
// Store it in 'host'
string host = Console.ReadLine();
try
{
// Get the DNS information
IPHostEntry ipHost = Dns.GetHostByName(host);
// Display the host name
Console.WriteLine("Host name: {0}", ipHost.HostName);
// Store the list of IP adresses
IPAddress[] ipAddr = ipHost.AddressList;
// Loop to actually display the IP
for(int x = 0; x < ipAddr.Length; x++)
{
Console.WriteLine("IP address: {0}", ipAddr[x].ToString());
}
}
// Catch the exception (if host was not found)
catch(System.Net.Sockets.SocketException)
{
Console.WriteLine("Host not found.");
}
}
} 

How To Use the Settings Class in C#

http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx
http://www.codeproject.com/KB/cs/PropertiesSettings.aspx 
http://codehill.com/2009/01/saving-user-and-application-settings-in-winforms/

SQL SERVER – Restore Database Backup using SQL


Database YourDB has full backup YourBaackUpFile.bak. It can be restored using following two steps.
Step 1: Retrive the Logical file name of the database from backup.
RESTORE DATABASE dbname
FROM DISK = 'D:BackUpYourBaackUpFile.bak'
WITH REPLACE
GO

Step 2: Use the values in the LogicalName Column in following Step.
----Make Database to single user Mode
ALTER DATABASE YourDB
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
----Restore Database
RESTORE DATABASE YourDBName
FROM DISK = 'D:BackUpYourBaackUpFile.bak'
WITH MOVE 'YourMDFLogicalName' TO 'D:DataYourMDFFile.mdf',
MOVE 'YourLDFLogicalName' TO 'D:DataYourLDFFile.ldf'
/*If there is no error in statement before database will be in multiuser
mode.
If error occurs please execute following command it will convert
database in multi user.*/
ALTER DATABASE YourDB SET MULTI_USER
GO


SQL Server 2000 Backup and Restore:

http://technet.microsoft.com/en-us/library/cc966495.aspx

Read XML from a file by using C#

http://www.kirupa.com/net/reading_xml_directly_pg1.htm
http://www.developer.com/net/csharp/article.php/3489611/Manipulate-XML-File-Data-Using-C.htm
http://support.microsoft.com/kb/307548

To Read a XML file:
 XmlDocument doc = new XmlDocument();
            doc.Load("D:\\Dotnet Projects\\final\\ClientAppl\\Header.xml");

            XmlNodeList bookList = doc.GetElementsByTagName("Header");

            foreach (XmlNode node in bookList)
            {

                XmlElement bookElement = (XmlElement)node;
                string title = bookElement.InnerText;
                lblHeader.Text = title;
            }