我正在尝试将PostgreSQL数据库连接到C#控制台应用程序。这是我的代码:
WL.Client.login("wl_directUpdateRealm", {onSuccess:..., onFailure:...});
我确实从Postgres复制了反向工程的SQL查询,所以我怀疑这是问题所在。无论如何,当我运行它时,我得到一个例外:
未处理的类型' Npgsql.PostgresException'发生在Npgsql.dll
中
在最后一行(executeNonQuery)。 有什么想法吗?
答案 0 :(得分:3)
查看你的SQL字符串 - 你错过了一个(?
string sql = string.Format("CREATE TABLE public.stvari2 ime text, broj smallint, id integer)");
在这里你不需要另一个( - > public.stvari2(ime
string sql = string.Format("CREATE TABLE public.stvari2( ime text, broj smallint, id integer)");
答案 1 :(得分:0)
尝试这样它会起作用
static void Main(string[] args)
{
String connections = "Server=192.168.1.163;Port=5432;Database=postgres;User Id=postgres;Password=root;";
NpgsqlConnection connection = new NpgsqlConnection();
connection.ConnectionString = connections;
connection.Open();
try
{
NpgsqlCommand cmd = new NpgsqlCommand();
cmd.Connection = connection;
cmd.CommandText = "INSERT INTO sector(name,address,designition,description,auto_id) values ('vinoth','chennai','sds','wdewd','123')";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (Exception e)
{
e.ToString();
}
}