此代码不起作用。谁能指导我在哪里可以找到使用 C# 即时创建 Postgresql 数据库和表的示例?
const string connStr = "Server=localhost;Port=5432;
User Id=postgres;Password=enter;Database=postgres";
var m_conn = new NpgsqlConnection(connStr);
// creating a database in Postgresql
m_createdb_cmd = new NpgsqlCommand("CREATE DATABASE IF NOT EXISTS \"testDb\" " +
"WITH OWNER = \"postgres\" " +
"ENCODING = 'UTF8' " +
"CONNECTION LIMIT = -1;", m_conn);
// creating a table in Postgresql
m_createtbl_cmd = new NpgsqlCommand(
"CREATE TABLE MyTable(CompanyName VARCHAR(150))";
m_conn.Open();
m_createdb_cmd.ExecuteNonQuery();
m_createtbl_cmd.Connection = m_conn;
m_conn.Close();
数据库已创建,但在创建表时出现静默失败。