Getting started with the BangDB for csharp on windows


Please download the BangDB for C# for Windows file and un-compress it using 7zip. If you don't have 7zip then you can get it from 7zip-org. Please ensure that you pick the right binary for 32/64 bit as you may need

The download files are (once un-compressed):

  • BangDB_CSharp.dll - The C# wrapper for bangdb
  • bangdbwin.dll - The BangDB dll
  • bangdbwin.lib - The BangDB lib file
  • bangdbwin.exp - The BangDB exported functions file
  • bangdb.config - The config file for BangDB
  • README.txt - General info for the db and the release
  • Test_BangDB - folder which contains the test file and VS project solution for the BangDB sample test ready to run


Store the un-compressed files and folder wherever you like. You can also create path variable to locate these files but it's not required. There is no separate install file for the binary

Running the sample test file

To quickly run the BangDB test, download the binary (32/64 bits) from above and go to the Test_BangDB folder. Open the project solution and build the project. The test app has been built using VS 2012, but it can be run using previous VS as well. If you are unable to open the VS solution/project file then you need to start from scratch. Further you can extend the test cases to check out more use cases and use BangDB in your own project.

Note that if you have created db without specifying the dbPath (the location where the db will keep it's data) then db will use the location provided in the config file. Either edit config file to put the dir loc (SERVER_DIR config) or provide it through the API. If the location provided in the config file by default (c:\\BangDBData) is not available on the disk then test will fail. The test app does require that you create c:\\BangDBData folder on your disk

To build an application for BangDB from scratch, below are the steps to create an application using Visual Studio

  • Create an empty csharp console project
  • Change the config to target x64 or x86 based on whether you would like the app for 64 bit or 32 bit respectively
  • Add reference to the BangDB_CSharp.dll from the project. To do this go to Add Reference-->Browse-->locate the dll on your machine. Location for the dll would be folder where you have kept all the uncompressed files after the download
  • Copy and paste the .cs files frol the Test_BangDB folder in your project dir
  • Finally edit the program.cs file and change the path variable according to the folder info where you have kept all the downloaded files/dlls (string path = "C:\\BangDB_DLLs" etc...)

The above is not required if you are able to open the solution/project file and build as provided in the Test_BangDB dir

Project should build now. You should now be able to run the test. To insert 1,000,000 items using 4 threads, issue the command (or set the command line arg in VS and run from VS) like following;

	# to run with the default command arguments
	$ with command arguments to put and get 1M keys and values
	c:\project_dir>\bin\x64\Release\test-bangdb-csharp.exe 1000000 4 put
	c:\project_dir>\bin\x64\Release\test-bangdb-csharp.exe 1000000 4 get

Sample Code

Below is sample code to do some simple operations using BangDB. The bangdb.config file defines many configurable parameters, but most importantly edit the following values based on your liking;

  • SERVER_DIR - This is basically the location where the db will keep its files. User can also provide the dir information while creating the databas object
  • KEY_SIZE - This is to denote the maximum length of key that you will be using to store values. The min value is 8 bytes, and maximum is dependent upon the PAGE_SIZE defined. however keep it small for better performance
  • BUFF_POOL_SIZE_HINT - The size of the buffer pool, default value is 1GB for 64 bit and 512MB for 32 bit, change as you wish

Please look at the document which describes meaning of various parameters in the config file at resources or go to the configuration section for detailed information and explanation

	/* Set the path, change it accordingly */
	string path = "C:\\BangDB_DLLs";	
	/* get a db, table and connection */
	Database db = new Database("mydb", path);
	Table tbl = db.GetTable("mytbl");
	Connection conn = tbl.GetConnection();
	byte[] k = Encoding.UTF8.GetBytes("key_1");
	byte[] v = Encoding.UTF8.GetBytes("The test value is 1");
	/* put and get value */
	if(conn.Put(k, v, InsertOptions.InsertUnique) < 0)
		Console.Writeline("error in put");
	byte[] rval = null;
	if(!conn.Get(k, out rval));
		Console.Writeline("error in get");
		Console.Writeline("error, value doesn't match");
	/* update the value */
	v = Encoding.UTF8.GetBytes("The test value is 2");
	if(conn.Put(k, v, InsertOptions.UpdateExisting) < 0)
		Console.Writeline("error in update");
	/* delete the key */
	if(conn.Del(k) < 0)
		Console.Writeline("error in del");

Also look at the general getting started and the test files available above