csharp.mdx 7.4 KB
Newer Older
D
dingbo 已提交
1 2 3 4 5 6 7 8 9 10
---
toc_max_heading_level: 4
sidebar_position: 7
sidebar_label: C#
title: C# Connector
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

D
dingbo 已提交
11
import Preparation from "./_preparation.mdx"
12 13 14 15 16 17
import CSInsert from "../../07-develop/03-insert-data/_cs_sql.mdx"
import CSInfluxLine from "../../07-develop/03-insert-data/_cs_line.mdx"
import CSOpenTSDBTelnet from "../../07-develop/03-insert-data/_cs_opts_telnet.mdx"
import CSOpenTSDBJson from "../../07-develop/03-insert-data/_cs_opts_json.mdx"
import CSQuery from "../../07-develop/04-query-data/_cs.mdx"
import CSAsyncQuery from "../../07-develop/04-query-data/_cs_async.mdx"
D
dingbo 已提交
18 19


20
`TDengine.Connector` is a C# language connector provided by TDengine that allows C# developers to develop C# applications that access TDengine cluster data.
D
dingbo 已提交
21

22
The `TDengine.Connector` connector supports connect to TDengine instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless writing, bind interface, etc. The `TDengine.Connector` currently does not provide a REST connection interface. Developers can write their RESTful application by referring to the [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) documentation.
D
dingbo 已提交
23

24
This article describes how to install `TDengine.Connector` in a Linux or Windows environment and connect to TDengine clusters via `TDengine.Connector` to perform basic operations such as data writing and querying.
D
dingbo 已提交
25

26
The source code of `TDengine.Connector` is hosted on [GitHub](https://github.com/taosdata/taos-connector-dotnet).
D
dingbo 已提交
27

28
## Supported Platforms
D
dingbo 已提交
29

30
The supported platforms are the same as those supported by the TDengine client driver.
D
dingbo 已提交
31

32
## Version support
D
dingbo 已提交
33

34
Please refer to [version support list](/reference/connector#version-support)
D
dingbo 已提交
35

36 37
## Supported features

D
dingbo 已提交
38
1. Connection Management
39 40 41 42
2. General Query
3. Continuous Query
4. Parameter Binding
5. Subscription
D
dingbo 已提交
43 44
6. Schemaless

45
## Installation Steps
D
dingbo 已提交
46

47
### Pre-installation preparation
D
dingbo 已提交
48

49 50 51
* Install the [.NET SDK](https://dotnet.microsoft.com/download)
* [Nuget Client](https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools) (optional installation)
* Install TDengine client driver, please refer to [Install client driver](/reference/connector#Install client driver) for details
D
dingbo 已提交
52

53
### Install via dotnet CLI
D
dingbo 已提交
54 55

<Tabs defaultValue="CLI">
56
<TabItem value="CLI" label="Get C# driver using dotnet CLI">
D
dingbo 已提交
57

58
You can reference the `TDengine.Connector` published in Nuget to the current project via the `dotnet` command under the path of the existing .NET project.
D
dingbo 已提交
59 60 61 62 63

``` bash
dotnet add package TDengine.Connector
```

64
</TabItem>
65
<TabItem value="source" label="Use source code to get C# driver">
D
dingbo 已提交
66

67
You can download TDengine's source code and directly reference the latest version of the TDengine.Connector library
D
dingbo 已提交
68 69 70 71 72 73 74 75 76 77 78 79

```bash
git clone https://github.com/taosdata/TDengine.git
cd TDengine/src/connector/C#/src/
cp -r TDengineDriver/ myProject

cd myProject
dotnet add TDengineDriver/TDengineDriver.csproj
```
</TabItem>
</Tabs>

80
## Create a connection
D
dingbo 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

``` C#
using TDengineDriver;

namespace TDengineExample
{

    internal class EstablishConnection
    {
        static void Main(String[] args)
        {
            string host = "localhost";
            short port = 6030;
            string username = "root";
            string password = "taosdata";
            string dbname = "";

            var conn = TDengine.Connect(host, username, password, dbname, port);
            if (conn == IntPtr.Zero)
            {
                Console.WriteLine("Connect to TDengine failed");
            }
            else
            {
                Console.WriteLine("Connect to TDengine success");
            }
            TDengine.Close(conn);
            TDengine.Cleanup();
        }
    }
}

```

115
## Usage examples
D
dingbo 已提交
116

117
### Write data
D
dingbo 已提交
118

119
#### SQL Write
D
dingbo 已提交
120 121 122

<CSInsert />

123
#### InfluxDB line protocol write
D
dingbo 已提交
124 125 126

<CSInfluxLine />

127
#### OpenTSDB Telnet line protocol write
D
dingbo 已提交
128 129 130

<CSOpenTSDBTelnet />

131
#### OpenTSDB JSON line protocol write
D
dingbo 已提交
132 133 134

<CSOpenTSDBJson />

135
### Query data
D
dingbo 已提交
136

137
#### Synchronous Query
D
dingbo 已提交
138 139 140

<CSQuery />

141
#### Asynchronous query
D
dingbo 已提交
142 143 144

<CSAsyncQuery />

145
### More sample programs
D
dingbo 已提交
146

147 148 149 150 151 152 153 154 155 156 157
|Sample program |Sample program description |
|--------------------------------------------------------------------------------------------------------------------|------------ --------------------------------|
| [C#checker](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/C%23checker) | Using TDengine.Connector, you can test C# Driver's synchronous writes and queries |
| [TDengineTest](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/TDengineTest) | A simple example of writing and querying using TDengine.
| [insertCn](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/insertCn) | Example of writing and querying Chinese characters using TDengine.
| [jsonTag](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/jsonTag) | Example of writing and querying JSON tag type data using TDengine.
| [stmt](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/stmt) | Example of parameter binding using TDengine.
| [schemaless](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/schemaless) | Example of writing with schemaless implemented using TDengine. |schemaless
| [benchmark](https://github.com/taosdata/TDengine/tree/develop/examples/C%23/taosdemo) | A simple benchmark implemented using TDengine.
| [async query](https://github.com/taosdata/taos-connector-dotnet/blob/develop/examples/QueryAsyncSample.cs) | Example of an asynchronous query implemented using TDengine. Example of an asynchronous query
| [subscribe](https://github.com/taosdata/taos-connector-dotnet/blob/develop/examples/SubscribeSample.cs) | Example of subscribing to data using TDengine. Data example
D
dingbo 已提交
158

159
## Important update records
D
dingbo 已提交
160

161
| TDengine.Connector | Description |
D
dingbo 已提交
162
|--------------------|--------------------------------|
163 164 165 166 167
| 1.0.6 | Fix schemaless bug in 1.0.4 and 1.0.5. |
| 1.0.5 | Fix Windows sync query Chinese error bug. | 1.0.4 | Fix schemaless bug.
| 1.0.4 | Add asynchronous query, subscription, and other functions. Fix the binding parameter bug.
| 1.0.3 | Add parameter binding, schemaless, JSON tag, etc. | new
| 1.0.2 | Add connection management, synchronous query, error messages, etc.   ## Other
D
dingbo 已提交
168

169
## Other descriptions
D
dingbo 已提交
170

171
### Third-party driver
D
dingbo 已提交
172

173
`Taos` is an ADO.NET connector for TDengine, supporting Linux and Windows platforms. Community contributor `Maikebing@@maikebing contributes the connector`. Please refer to:
D
dingbo 已提交
174

175 176
* Interface download:<https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos>
* Usage notes:<https://www.taosdata.com/blog/2020/11/02/1901.html>
D
dingbo 已提交
177

178
## Frequently Asked Questions
D
dingbo 已提交
179

180
1. "Unable to establish connection", "Unable to resolve FQDN"
D
dingbo 已提交
181

182
  Usually, it cause by the FQDN configuration is incorrect, you can refer to [How to understand TDengine's FQDN (Chinese)](https://www.taosdata.com/blog/2021/07/29/2741.html) to solve it. 2.
D
dingbo 已提交
183

184
Unhandled exception. System.DllNotFoundException: Unable to load DLL 'taos' or one of its dependencies: The specified module cannot be found.
D
dingbo 已提交
185

D
dingbo 已提交
186
  This is usually because the program did not find the dependent client driver. The solution is to copy `C:\TDengine\driver\taos.dll` to the `C:\Windows\System32\` directory on Windows, and create the following soft link on Linux `ln -s /usr/local/taos/driver/libtaos.so.x.x .x.x /usr/lib/libtaos.so` will work.
D
dingbo 已提交
187

188
## API Reference
D
dingbo 已提交
189

190
[API Reference](https://docs.taosdata.com/api/connector-csharp/html/860d2ac1-dd52-39c9-e460-0829c4e5a40b.htm)