我想將PostgreSQL數據庫連接到C#控制檯應用程序。這是我的代碼:C中的postgres異常#
static void Main(string[] args)
{
string connstring = String.Format("Server=localhost;Port=5432;" +
"User Id=postgres;Password=admin;Database=mydb;");
NpgsqlConnection conn = new NpgsqlConnection(connstring);
conn.Open();
string sql = string.Format("CREATE TABLE public.stvari2 ime text, broj smallint, id integer)");
NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
我從字面上複製了來自Postgres的反向工程SQL查詢,所以我懷疑這是問題所在。總之,當我運行它,我得到一個異常:
類型的未處理的異常「Npgsql.PostgresException」發生在Npgsql.dll
在最後一行(的ExecuteNonQuery)。 任何想法?在您的SQL字符串