is there any example about PgSqlLoader.LoadTable use?

is there any example about PgSqlLoader.LoadTable use?

Postby 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
waertf
 
Posts: 9
Joined: Sat 07 Jun 2014 01:52

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

Postby 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())
    {
...
Pinturiccio
Devart Team
 
Posts: 1979
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL