[英]Severity Code Description Project File Line Suppression State Error The tag 'VideoResultControl' does not exist in XML
[英]database "openpg" does not exist Severity: FATAL Code: 3D000
我正在尝试以编程方式创建 postGres 数据库 c#,以前我手动创建了数据库并使用连接字符串打开它并对其进行操作,它运行良好。
现在我必须首先检查该 DBB 是否已经存在,如果不存在,则首先创建它,然后执行其他操作,例如读取写入。
我这样做的代码是:
internal void createDataBaseIfDoNotExist()
{
string connStr = string.Empty;
connStr =
"Server=" + "localhost"
+ ";Port=" + "5432"
+ ";User Id=" + "openpg"
+ ";Password=" + "oppwd"
+ ";";
var m_conn = new NpgsqlConnection(connStr);
var m_createdb_cmd = new NpgsqlCommand(@"CREATE DATABASE IF NOT EXISTS testDb ;", m_conn);
try
{
m_conn.Open();
m_createdb_cmd.ExecuteNonQuery();
m_conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Errr on createDataBaseIfDoNotExist query :" + ex);
}
}
And it gives followign error:
database "openpg" does not exist Severity: FATAL Code: 3D000
而我保留的数据库名称是“testDb”,而不是“openpg”
以前我创建了一个数据库名称“NewDB”并创建了这样的连接字符串:
connStr =
"Database=" + "NewDB"
+ ";Server=" + "localhost"
+ ";Port=" + "5432"
+ ";User Id=" + "openpg"
+ ";Password=" + "oppwd"
+ ";";
它工作正常,那么为什么现在有错误以及如何解决它?
您需要在连接字符串中添加Database=postgres
connStr = "Server=localhost;Port=5432;User Id=postgres;Password=password_of_the_user;Database=postgres";
因为postgres
是PostgreSQL 默认的管理连接数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.