c# - 使用 npgsql 创建名称区分大小写的 PostgreSQL 数据库

标签 c# postgresql npgsql

我正在尝试使用 npgsql 库创建一个 PostgreSQL 数据库,但数据库名称总是以小写结尾。是否可以保留大小写或者我应该将所有内容都小写?我希望数据库名称是 MyDatabase,但它总是以 mydatabase 结尾。

string server = "localhost";
string database = "MyDatabase";
string connectionString = @"Server=" + server + ";User Id=postgres";
var connection = new NpgsqlConnection(connectionString);
string commandText = "CREATE DATABASE " + database;
var command = new NpgsqlCommand(commandText);
connection.Open();
command.Connection = connection;
command.ExecuteNonQuery();
connection.Close();

最佳答案

如下引用数据库名称:

string commandText = string.Format("CREATE DATABASE \"{0}\"", database);

关于c# - 使用 npgsql 创建名称区分大小写的 PostgreSQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21808696/

相关文章:

c# iOS 10 通知 - GetDictionaryOfValuesFromKeys() 错误

c# - 在 Entity Framework 中使用三元条件运算符或表达式

c# - 如何暂停 BackgroundWorker?或者类似的东西

postgresql - 在 PostgreSQL 中重用旧的 master 作为 slave

c# - 是否值得保存 typeof() 调用的结果以供多次使用?

sql - 如何在 PostgreSQL 的换行符上将一个值拆分为多行?

php - 为什么我应该在 pg_connect() 函数中使用 connect_timeout=5?

postgresql - Npgsql.PostgresException (0x80004005) : XX000: cache lookup failed for type 207852 when schema dropped

NHibernate ISessionFactory.OpenSession() 不打开数据库连接

PostgreSQL 和 dev.nauck.AspSQLProvider 的 ASP.NET 成员资格