如何在 Visual Studio 中使用 C# 从 Snowflake 数据库/架构中获取所有表的列表

问题描述 投票:0回答:1

我可以在 Snowflake 中运行此查询,没有任何问题:

select TABLE_NAME
from information_schema.tables
where table_catalog = 'DB' and table_schema = 'SCHEMA';

但是当使用 C# 通过 Visual Studio 运行相同的查询时,读者似乎是空的:

string Query = "select TABLE_NAME from information_schema.tables where table_catalog = 'DB' and table_schema = 'SCHEMA';";

IDbCommand Cmd = Conn.CreateCommand();
Cmd.CommandText = Query;

IDataReader Reader = Cmd.ExecuteReader();

while (Reader.Read())
{
    Console.WriteLine("test");   // this never gets printed!
}

但是,我可以从常规表的查询中读取数据,例如

SELECT * FROM TABLE;

有没有办法在 Visual Studio 中读取

information_schema
?或者获取 Snowflake 数据库/模式中所有表的列表的替代方法?

c# sql snowflake-cloud-data-platform
1个回答
0
投票

此查询应返回您需要的表信息

information_schema
:

select table_schema, table_name
from information_schema.tables
where table_type = 'BASE TABLE'

您没有说明您正在使用哪个 Snowflake 驱动程序。 SQL 应该是独立的,但执行查询的方式可能有所不同,或者某些驱动程序可能提供内置帮助。

(警告:我在使用

Snowflake.Data
库时遇到了几个问题。)

© www.soinside.com 2019 - 2024. All rights reserved.