Earlier, in npgsql 2.2 I could create a new PostgreSQL database through c# code like this:
string strconn = String.Format("Server={0};Port={1};User Id={2};Password={3};",
strServer, strPort, strUser, strPass);
NpgsqlConnection admconn = new NpgsqlConnection(strconn);
admconn.Open();
NpgsqlCommand command = new NpgsqlCommand("CREATE DATABASE " + strNewDB, admconn);
command.ExecuteNonQuery();
admconn.Close();
So, you see, there's no Database name in connection string. But when I was migrated to npgsql 3.0 this is not work: on opening the connection the exception occured: "Database can't be null".
If I specify in connection string default database "postgres" it works, but the joke is that it can be no default postgres database or even databases at all in PostgreSQL and it would be better not specify database to create new one.
And the same situation in creating user through c# code.
Any ideas?
template1is always there, so you can connect to that, and then run thecreate databasestatement.