Performing BULK operations with SQL can be useful when you are trying to insert any type of file. Don’t mess up with the complex code, just use a simple SQL query to insert any file type in SQL table.
To perform this operation first you need to have a column with datatype as varbinary(max)
. See below example:
Create a table with an ID and Data as columns with INT
and VARBINARY(MAX)
as their Datatypes respectively.
Create table tblData ( FileId int, FileData varbinary(max) )
Perform INSERT to Save a file. Here just change the location of the file you want to insert.
Insert into tblData (FileId, FileData) SELECT 1, BulkColumn FROM OPENROWSET(BULK N'D:\Software\siw.exe', SINGLE_BLOB) AS Document
Display table data after INSERT
Select * from tblData
GUID pronounced as goo’id - Globally unique identifier is a 128-bit integer that can be used to uniquely identify something. If you want to identify the large collection of data GUID is the best approach in my view. Also you can use the autoincremental integer to identify records, this is the basic approach programmer’s use.
GUID method can be found under the System namespace and it also provides some overloads. Here is how we can use the GUID overloads:
System.Guid.NewGuid().ToString(); //c93ded50-7cce-4f3a-b8aa-5a1a34d80b14 System.Guid.NewGuid().ToString("N"); //636bdfd2bbc541229fbc6b869995ce6f System.Guid.NewGuid().ToString("D"); //45e602b6-0904-47ac-a764-a5522f56f40f System.Guid.NewGuid().ToString("B"); //{68f55508-f72c-4a38-b96b-f493c3c5adb9} System.Guid.NewGuid().ToString("P"); //(1c2e52a7-e384-445e-b80a-e8704c6ecbd6)
To create GUID in SQL Server use the simple select statement:
SELECT NEWID()
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)
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");
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)