Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create a PostgreSQL database using the npgsql library, but the database name always ends up in lower case. Is it possible to preserve the case or should I just lower case everything? I want the database name to be MyDatabase, but it always ends up as 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();
share|improve this question
1  
You need to quote the DB name. –  Milen A. Radev Feb 16 at 8:06
add comment

1 Answer

Quote the DB name as below:

string commandText = string.Format("CREATE DATABASE \"{0}\"", database);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.