is there any example about PgSqlLoader.LoadTable use?

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
waertf
Posts: 9
Joined: Sat 07 Jun 2014 01:52

is there any example about PgSqlLoader.LoadTable use?

Post by waertf » Thu 31 Jul 2014 08:45

I create a table like below

Code: Select all

string pgCreateDeviceStatusTable = @"CREATE TABLE
IF NOT EXISTS ""custom"".""WhatsUpDeviceStatus"" (
	""id"" TEXT COLLATE ""default"" NOT NULL,
	""name"" TEXT COLLATE ""default"",
	""stateID"" TEXT COLLATE ""default"",
	""stateName"" TEXT COLLATE ""default"",
	CONSTRAINT ""WhatsUpDeviceStatus_pkey"" PRIMARY KEY (""id"")
) WITH (OIDS = FALSE);

ALTER TABLE ""custom"".""WhatsUpDeviceStatus"" OWNER TO ""postgres"";";
and use following code to load

Code: Select all

public void LoadDatatable(DataTable dt)
        {
            using (PgSqlConnection pgSqlConnection = new PgSqlConnection(pgCSB.ConnectionString))
            {
                using (PgSqlLoader loader = new PgSqlLoader())
                {
                    try
                    {
                        loader.Connection = pgSqlConnection;
                        loader.TableName = "WhatsUpDeviceStatus";
                        pgSqlConnection.Open();
                        loader.Open();
                        loader.CreateColumns();
                        loader.LoadTable(dt);
                    }
                    catch (Exception e)
                    {

                        Console.WriteLine("error:" + e.ToString());
                        SiAuto.Main.LogException(e);
                    }
                    finally
                    {
                        loader.Close();
                        pgSqlConnection.Close();
                    }
                }
            }
        }
then it show error on "loader.Open();"
Devart.Data.PostgreSql.PgSqlException (0x80004005): relation "WhatsUpDeviceStatus" not existed

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: is there any example about PgSqlLoader.LoadTable use?

Post by Pinturiccio » Fri 01 Aug 2014 15:11

Probably the reason of the exception is that the WhatsUpDeviceStatus table belongs to the 'custom' schema, and your connection uses other schema. If you haven't specified a schema for your connection, the 'public' schema is used.
Please try specifying the 'custom' schema for your connection. Here is an example:

Code: Select all

using (PgSqlConnection pgSqlConnection = new PgSqlConnection(pgCSB.ConnectionString))
{
    pgSqlConnection.Schema = "custom";
    using (PgSqlLoader loader = new PgSqlLoader())
    {
...

Post Reply