http://visualstudiohacks.com/general/customize-your-project-build-process/
http://bytes.com/topic/c-sharp/answers/424841-post-build-events
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."); } } }
RESTORE DATABASE dbname
FROM DISK = 'D:BackUpYourBaackUpFile.bak'
WITH REPLACE
GO
----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
Microsoft.SqlServer.management
Microsoft.SqlServer.Management.NotificationServices
Microsoft.SqlServer.Management.Smo
Microsoft.SqlServer.Management.Smo.Agent
Microsoft.SqlServer.Management.Smo.Broker
Microsoft.SqlServer.Management.Smo.Mail
Microsoft.SqlServer.Management.Smo.RegisteredServers
Microsoft.SqlServer.Management.Smo.Wmi
Microsoft.SqlServer.Management.Trace
public void BackupDatabase(String databaseName, String userName,
String password, String serverName, String destinationPath)
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "ArchiveDataBase:" +
DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
}
public void RestoreDatabase(String databaseName, String filePath,
String serverName, String userName, String password,
String dataFilePath, String logFilePath)
{
Restore sqlRestore = new Restore();
BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + databaseName + ".mdf";
String logFileLocation = logFilePath + databaseName + "_Log.ldf";
db = sqlServer.Databases[databaseName];
RelocateFile rf = new RelocateFile(databaseName, dataFileLocation);
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName, dataFileLocation));
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName+"_log", logFileLocation));
sqlRestore.ReplaceDatabase = true;
sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
sqlRestore.PercentCompleteNotification = 10;
sqlRestore.PercentComplete +=
new PercentCompleteEventHandler(sqlRestore_PercentComplete);
sqlRestore.SqlRestore(sqlServer);
db = sqlServer.Databases[databaseName];
db.SetOnline();
sqlServer.Refresh();
}
The portion of code uses full backup features. If you want, you can perform incremental and differential backup as well.ServerConnection
:SqlConnection sqlCon = new SqlConnection ("Data Source=Bappi; Integrated Security=True;");
ServerConnection connection = new ServerConnection(sqlCon);
Modify the ServerConnection
portion of both code samples using this code in order to use Windows Security.