# api-csharp **Repository Path**: dolphindb/api-csharp ## Basic Information - **Project Name**: api-csharp - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 2 - **Created**: 2020-06-18 - **Last Updated**: 2026-01-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # DolphinDB C# API ### 1. C# API Introduction The C# API implements messaging and data conversion between .Net program and DolphinDB server. C# API runs on .Net Framework 4.0 and above. The C# API adopts interface-oriented programming. It uses the interface class "IEntity" to represent all data types returned by DolphinDB. Based on the "IEntity" interface class and DolphinDB data forms, the C# API provides 7 extension interfaces: scalar, vector, matrix, set, dictionary, table and chart. These interface classes are included in the package of com.xxdb.data. Extended Interface Classes | Naming Rules | Examples ---|---|--- scalar|Basic\|BasicInt, BasicDouble, BasicDate, etc. vector, matrix|Basic\\|BasicIntVector, BasicDoubleMatrix, BasicAnyVector, etc. set, dictionary and table|Basic\|BasicSet, BasicDictionary, BasicTable. chart| |BasicChart| "Basic" indicates the basic data type interface, \ indicates a DolphinDB data type, and \ indicates a DolphinDB data form. The most important object provided by the DolphinDB C# API is DBConnection. It allows C# applications to execute script and functions on DolphinDB servers and transfer data between C# applications and DolphinDB servers. DBConnection provides the following methods: | Method Name | Details | |:------------- |:-------------| |connect(host, port, [username, password])|Connect the session to DolphinDB server| |login(username,password,enableEncryption)|Log in to the server| |run(script)|Run script on DolphinDB server| |run(functionName,args)|Call a function on DolphinDB server| |upload(variableObjectMap)|Upload local data to DolphinDB server| |isBusy()|Determine if the current session is busy| |close()|Close the current session| ### 2. Establish DolphinDB connection The C# API connects to the DolphinDB server via TCP/IP protocol. To connect to a local DolphinDB server with port number 8848: ``` using dolphindb; using dolphindb.data; using dolphindb.io; public void Test_Connect(){ DBConnection conn=new DBConnection(); Assert.AreEqual(true,conn.connect("localhost",8848)); } ``` Establish a connection with a username and password: ``` boolean success = conn.connect("localhost", 8848, "admin", "123456"); ``` If an application calls user-defined functions, we can pass the script with function definitions to the parameter 'initialScript'. The advantages of this are: First, we do not need to repeatedly define these functions each time we call function `run`. Second, the API provides an automatic reconnection mechanism, which generates a new session when it is reconnected after a network disruption. If the parameter 'initialScript' is specified, the API will automatically execute the script to redefine these functions in the new session. This parameter can be very useful when network connection is not very stable but the application needs to run continuously. ``` boolean success = conn.connect("localhost", 8848, "admin", "123456", ""); ``` ### 3.Run DolphinDB script To run DolphinDB script in C#: ``` conn.run("