Backup/Restore SQL database using C#

21. June 2009 15:59

C# SQL Server Utils  57 Comments

Microsoft’s .NET framework provides the flexibility to Backup and Restore SQL server database. A few lines to populate the names of all the server instances, create backups and then restore the backups. The application what you see here is a part of an application, so when you create backups and restore it will use the same path hardcoded in the code itself. You can change the way you like it.


Namespace you need to add:  

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.IO;

I am not going to write on and on and just make it going boring, so it's better just download the code and check the comments, they are one liners, but clears everything. 

Download Full Application Here: DBBackup.zip (290.99 kb)

Currently rated 3.8 by 17 people

Microsoft Surface

21. June 2009 15:33

Microsoft   0 Comments

I know it is too late to post this, but still it's new for many people out there. Cool

 

[flv:Microsoft_Surface.flv]

 No Rating

Set the default printer for printing programatically

16. June 2009 15:17

C# Code Snippets  0 Comments

You need to print the document but you don't want to go to control panel or printer and faxes options and just want to get it changed automatically. You can even set the shared local network printer with this code.

Just with the code you can override the system settings and change the default printer for your system.

You need to use the namespace so in order to use the DLLImport attribute.

using System.Runtime.Interopservices;
//Set default printer to the one available with your system or network.
[DllImport("Winspool.drv")]
private static extern bool SetDefaultPrinter(string printerName);

Now on button click or on form load just change the printer you want to use while printing and then change it back to the one before.

//Set the default printer. I have set it as my Adobe PDF printer
SetDefaultPrinter("Adobe PDF");
Currently rated 5.0 by 1 person

Eject and Pop-in your CD / DVD with a hotkey

13. June 2009 16:41

Utils  0 Comments

If you are annoyed with the malfunctioning of your CD/DVD ROM. This small utility will help you to eject and and again pop-in inside the ROM. Just press CTRL + Q to toggle. Place it anywhere you like on your system, I recommend to create a folder and then place a this utility inside it as it will installs on the first time you run the application and start-up with your windows the next time you boot in.

Download Link: CDAX.zip (113.18 kb)

 No Rating

Shoutdown/Logoff/Hibernate/Stand By - Use CODE to do 'em all

12. June 2009 17:32

C# Code Snippets  0 Comments

Step 1: Add the following line to use the namespace. This is necessary as we need to use the User32.dll with DLLImport attribute.

using System.Runtime.InteropServices;

Step 2: Now add the below line to your code to use the methods from the User32.dll

[DllImport("user32.dll")]
public static extern void LockWorkStation();
[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int uFlags, int dwReason);

Step 3: Once you complete the above two steps, you can now call the methods on button click or after some or with some particular event or the way you like.

LockWorkStation(); //Locks the workstation, Equivalent to WIN+L
ExitWindowsEx(0, 0)//Shutdowns the machine 
Application.SetSuspendState(PowerState.Suspend, true, true)  //Put the machine in stand-by mode
Application.SetSuspendState(PowerState.Hibernate, true, true); // Hibernates the system
 No Rating

Visit blogadda.com to discover Indian blogs Computers Blogs