Todos os produtos
Search
Central de documentação

Tablestore:.NET SDK

Última atualização: Jul 03, 2026

Utilize o Tablestore SDK for .NET para gerenciar dados em tabelas de colunas largas.

Guia de início rápido

Comece a usar o Tablestore SDK for .NET. Prepare seu ambiente, instale o SDK e inicialize o cliente.

Pré-requisitos

O SDK foi desenvolvido com base no .NET Standard 2.0 e oferece suporte às seguintes plataformas e runtimes:

Plataforma

Runtime

Windows

  • .NET Core 2.0 ou superior, ou .NET Framework 4.0 ou superior

  • Visual Studio 2010 ou superior

Linux e macOS

  • .NET Core 2.0 ou superior

Instalar o SDK

Instale o Tablestore SDK for .NET via NuGet ou a partir do código-fonte.

NuGet

Instale usando a CLI do .NET:

dotnet add package Aliyun.TableStore.SDK

Como alternativa, instale pelo Gerenciador de Pacotes NuGet no Visual Studio:

  1. Abra ou crie um projeto no Visual Studio e escolha Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

    Nota

    Caso o NuGet não esteja instalado no Visual Studio, baixe e instale-o a partir de NuGet.

  2. Pesquise por aliyun.tablestore e selecione Aliyun.TableStore.SDK nos resultados.

  3. Selecione a versão mais recente e clique em Install. O SDK será adicionado automaticamente ao seu projeto.

Código-fonte

Importe o código-fonte do SDK para o seu projeto.

  1. Clone o repositório do SDK no GitHub:

    git clone https://github.com/aliyun/aliyun-tablestore-csharp-sdk.git
    Nota

    Se o Git não estiver instalado, baixe e instale-o em Git.

  2. No Visual Studio, clique com o botão direito em Solution e selecione Add > Existing Project.

  3. Na caixa de diálogo, selecione o arquivo aliyun-tablestore-sdk.csproj e clique em Open.

  4. Clique com o botão direito em Project e selecione References > Add Reference. Na caixa de diálogo, alterne para a aba Projects e selecione aliyun-tablestore-sdk.

  5. Clique em OK.

Configurar credenciais de acesso

Criar uma AccessKey para sua conta Alibaba Cloud ou usuário RAM e configure-a como variável de ambiente para evitar a codificação fixa de credenciais.

Reinicie sua IDE, terminal, outros aplicativos de desktop e serviços em segundo plano após a configuração para carregar as variáveis de ambiente atualizadas. Para obter mais informações sobre outros tipos de credenciais de acesso, consulte Configurar credenciais de acesso .

Linux

  1. Adicione as variáveis de ambiente ao arquivo ~/.bashrc:

    echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bashrc
    echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bashrc
  2. Aplique as alterações:

    source ~/.bashrc
  3. Verifique as variáveis de ambiente:

    echo $TABLESTORE_ACCESS_KEY_ID
    echo $TABLESTORE_ACCESS_KEY_SECRET

macOS

  1. Verifique seu shell padrão:

    echo $SHELL
  2. Configure conforme o tipo de shell utilizado:

    Zsh

    1. Adicione as variáveis de ambiente ao arquivo ~/.zshrc:

      echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.zshrc
      echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.zshrc
    2. Aplique as alterações:

      source ~/.zshrc
    3. Verifique as variáveis de ambiente:

      echo $TABLESTORE_ACCESS_KEY_ID
      echo $TABLESTORE_ACCESS_KEY_SECRET

    Bash

    1. Adicione as variáveis de ambiente ao arquivo ~/.bash_profile:

      echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bash_profile
      echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bash_profile
    2. Aplique as alterações:

      source ~/.bash_profile
    3. Verifique as variáveis de ambiente:

      echo $TABLESTORE_ACCESS_KEY_ID
      echo $TABLESTORE_ACCESS_KEY_SECRET

Windows

CMD

  1. Defina as variáveis de ambiente no CMD:

    setx TABLESTORE_ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID"
    setx TABLESTORE_ACCESS_KEY_SECRET "YOUR_ACCESS_KEY_SECRET"
  2. Reinicie o CMD e verifique:

    echo %TABLESTORE_ACCESS_KEY_ID%
    echo %TABLESTORE_ACCESS_KEY_SECRET%

PowerShell

  1. Execute no PowerShell:

    [Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
    [Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", "YOUR_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
  2. Verifique as variáveis de ambiente:

    [Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
    [Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)

Inicializar o cliente

O Tablestore SDK for .NET é seguro para threads. Ao utilizar múltiplas threads, compartilhe uma única instância do OTSClient. Após inicializar o cliente, liste todas as tabelas da instância para verificar a conexão.

Importante

O acesso pela rede pública vem desativado por padrão em novas instâncias. Para acessar recursos da instância pela rede pública, ative o acesso público em Network Management.

using System;
using Aliyun.OTS;
using Aliyun.OTS.Request;
using Aliyun.OTS.Response;

namespace Aliyun.OTS.Samples
{
    public class Sample
    {
        public static void InitializeClient()
        {
            // Replace yourEndpoint with the instance endpoint
            string endpoint = "yourEndpoint";
            // Replace yourInstanceName with the instance name
            string instanceName = "yourInstanceName";
            // Obtain the AccessKey ID and AccessKey Secret from environment variables
            string accessKeyId = Environment.GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID");
            string accessKeySecret = Environment.GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET");
            OTSClientConfig config = new OTSClientConfig(endpoint, accessKeyId, accessKeySecret, instanceName)
            {
                OTSDebugLogHandler = null,
                OTSErrorLogHandler = null
            };

            try
            {
                // Initialize the Tablestore client
                OTSClient client = new OTSClient(config);
                // List and print all tables in the instance
                ListTableResponse response = client.ListTable(new ListTableRequest());
                foreach (var tableName in response.TableNames)
                {
                    Console.WriteLine(tableName);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("List table failed, exception:{0}", ex.Message);
            }
        }
    }
}

Compatibilidade de versões

A versão mais recente do SDK é a 6.x.x. Compatibilidade com versões anteriores:

Versão

Compatibilidade

Descrição

5.x.x

Compatível

N/D

4.x.x

Compatível

N/D

3.x.x

Compatível

N/D

2.x.x

Incompatível

As seguintes interfaces foram removidas: Condition.IGNORE, Condition.EXPECT_EXIST e Condition.EXPECT_NOT_EXIST. O arquivo DLL foi renomeado de Aliyun.dll para Aliyun.TableStore.dll.

Para consultar o histórico detalhado de versões, veja Histórico de versões do Tablestore SDK for .NET.

Perguntas frequentes

Problemas comuns relacionados ao Tablestore SDK for .NET:

Referências

Para obter informações sobre tratamento de erros no Tablestore, consulte Tratamento de erros.