Search found 52 matches

by kerrywales
Tue 16 Dec 2014 23:55
Forum: dotConnect for PostgreSQL
Topic: LEFT JOIN LATERAL(OUTER APPLY) error
Replies: 2
Views: 1703

Re: LEFT JOIN LATERAL(OUTER APPLY) error

Thank you. Absolutely spot on. With the Token in the edml file changed the runtime error disappeared and the query produced the correct results.

:D
by kerrywales
Mon 15 Dec 2014 09:49
Forum: dotConnect for PostgreSQL
Topic: LEFT JOIN LATERAL(OUTER APPLY) error
Replies: 2
Views: 1703

LEFT JOIN LATERAL(OUTER APPLY) error

Hi,
I have a VS 2013 compiling into an AnyCPU environment with .Net 4.5.1 and I am getting an error. I have Pg 9.3.5 so I am not sure if the error message is being incorrectly reported. Any pointers gratefully received.
{"LEFT JOIN LATERAL(OUTER APPLY) is not supported by PostgreSQL Database 9.2 and lower. PostgreSQL 9.3 or higher is required to run this LINQ statement correctly. If you need to run this statement with PostgreSQL Database 9.2 or lower, rewrite it so that it can be converted to SQL, supported by the version of PostgreSQL you use."}
I had Pg 9.2 but upgraded to 9.3.5. That is what pgAdmin reporting.

Devart Data is: 5.0.1095.0
Devart Data PostgreSQL: 7.3.303.0
same for .Entity

In 9.2 and the previous Devart there was a work around with linq kit based on:

Code: Select all

var query = 
  from Table1 in entity.TblTable1
  join Table2 in entity.TblTable2 on Table1.TblTable2.OID equals Table2.OID
  join Table3 in entity.TblTable3 on Table1.TblTable2.OID equals Table3.TblTable2.OID
  let leftOuterEmail = (from Table4 in entity.TblMail
    where Table3.TblName.OID == Table4.TblName.OID
      && ((Table3.TblName.IsDeceased != true
      && Table3.TblName.IsPerson)
      || !Table3.TblName.IsPerson)
      select new
      {
          EmailAdd = ((Table4.EmailAdd.Length > 0) ? Table4.EmailAdd : "")
      }).FirstOrDefault()

      where (ForEmail && leftOuterEmail.EmailAddress.Length > 0) || !ForEmail
        orderby Table1.TblTable2.Reference
        select new
        {
          OID = Table2.OID,
          OIDCT = Table2.TblTable1s.FirstOrDefault().TblContactType.OIDContactType,
          ..........
        };
by kerrywales
Thu 16 May 2013 08:58
Forum: dotConnect for PostgreSQL
Topic: Using MAX to find a record then get other columns in the row (c#)
Replies: 1
Views: 1384

Using MAX to find a record then get other columns in the row (c#)

Can someone help me with a Framework query into a PG db. I am using fw 3.5 with dotConnect in C#.

In its simplified format I have two tables. Transactions & Clients. When a Transaction is an order then ClientID is > 0. If it is not an order, then it is 0.

Transactions
TransactionID
TransactionDate
ClientID
TransactionAmount

Clients
ClientID
ClientName

I want a list of client names and latest +ve TransactionAmount.

This SQL will get me part of the way
select "ClientID", Max("TransactionDate") from "Transactions"
Where “ClientID” > 0 and "TransactionAmount" > 0.00 group by "ClientID "

In as much as this gives me a list of the dates of newest transactions and the Client ID.

1. I am having difficulty translating this into LINQ syntax so that it does the same task
2. How to use the LINQ to get the Transaction record (so I can select the TransactionAmount) and join it to the Clients table to get to the ClientID

Can anyone advise please.
by kerrywales
Fri 30 Nov 2012 14:59
Forum: dotConnect for PostgreSQL
Topic: PgSqlDump restore fails with Dump data's date format
Replies: 8
Views: 2019

Re: PgSqlDump restore fails with Dump data's date format

Thank you for investigating.

For other poor souls trying this I though I would let you know where I have got to and what I have found.

1. Make sure that ALL tables are owned by the same user and that ALL constraints are owned by the same user. It is possible to have constraints set up between two tables owned by different users which pg_dump and pg_restore do not mind but pgsqldump does.

2. Do not dump the data out as data only the restore moans like mad.

3. Do dump the information in separate files.

4. Check that people who manage the database do NOT put in funny characters. In doing this exercise I identified that a user had a constraint name with a '"' (double quotes) contained within it. Again pg_dump & pg_restore was happy with this. The Devart mechanism was not.

I use Views, indexes and constraints to define relationships within the DB. The restoring works once the name of the constraint was modified (see previous comment).

Extracts from my backup/restore test code:

Code: Select all

var dataBackup = new PgSqlDump()
                    { 
                        Connection = myConnection.getConnection(),
                        QuoteIdentifier = true,
                        IncludeBlob = true,
                        IncludeDrop = false, 
                        IncludeUsers = false, 
                        GenerateHeader = false,
                        ObjectTypes = PgSqlDumpObjects.All ^ PgSqlDumpObjects.Users ^ PgSqlDumpObjects.Languages 
                            ^ PgSqlDumpObjects.Views ^ PgSqlDumpObjects.Indexes ^ PgSqlDumpObjects.Constraints,
                        Mode =  DumpMode.All
                    };

                    string name = Path.Combine(Destination, "dump_data.backup");
                    dataBackup.Backup(name);

Code: Select all

var viewsBackup = new PgSqlDump()
                    {
                        Connection = myConnection.getConnection(),
                        QuoteIdentifier = true,
                        GenerateHeader = false,
                        ObjectTypes = PgSqlDumpObjects.Views
                    };

                    name = Path.Combine(Destination, "dump_views.backup");
                    viewsBackup.Backup(name);
                    

Code: Select all

var indiciesBackup = new PgSqlDump()
                    {
                        Connection = myConnection.getConnection(),
                        QuoteIdentifier = true,
                        GenerateHeader = false,
                        ObjectTypes = PgSqlDumpObjects.Indexes
                    };

                    name = Path.Combine(Destination, "dump_indicies.backup");
                    indiciesBackup.Backup(name);
                    

Code: Select all

var constraintsBackup = new PgSqlDump()
                    {
                        Connection = myConnection.getConnection(),
                        QuoteIdentifier = true,
                        GenerateHeader = false,
                        ObjectTypes = PgSqlDumpObjects.Constraints
                    };

                    name = Path.Combine(Destination, "dump_constraints.backup");
                    constraintsBackup.Backup(name);
                    
Restoring means I
1. Create an empty database of correct ownership etc

2. Restore in this order (I also zip up the backups):

Code: Select all

DoDevartRestore("Data", openWhat.InitialDirectory, openWhat.FileName, "dump_data.backup");
                    DoDevartRestore("Indicies", openWhat.InitialDirectory, openWhat.FileName, "dump_indicies.backup");
                    DoDevartRestore("Constraints", openWhat.InitialDirectory, openWhat.FileName, "dump_constraints.backup");
                    DoDevartRestore("Views", openWhat.InitialDirectory, openWhat.FileName, "dump_views.backup");
                    

Code: Select all

private bool DoDevartRestore(string myMessage, string myDirectory, string zipFile, string myFile)
        {
            bool result = false;
            try
            {
                ...
                string myFilePath = Path.Combine(myDirectory, myFile);
                try
                {
                    if (File.Exists(myFilePath))
                        File.Delete(myFilePath);
                }
                catch { };
                
                ...
                    RunDevartRestore();
                    result = true;
                }
            }
            catch { };
            return result;
        }

Code: Select all

public void RunDevartRestore()
        {
            try
            {
                CSLConnect myConnection = new CSLConnect(teUser.Text,tePassword.Text, tePort.Text, teHost.Text, teDB.Text);

                if (myConnection.Login())
                {
                    using (PgSqlDump DataRestore = new PgSqlDump { Connection = myConnection.getConnection() })
                    {
                        if (File.Exists(RestoreString))
                        {
...                            
                            DataRestore.Restore(RestoreString);
                            myConnection.Logout();
                            File.Delete(RestoreString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
        }
Timings

I have a pg_dump & pg_restore program with a wrapper as well. I tested the routine with the same database.
pg_dump & pg_restore to do both took less than 5 mins

Using the devart method it took 7 minutes to backup and 1 hr 10 mins to restore
by kerrywales
Fri 30 Nov 2012 08:30
Forum: dotConnect for PostgreSQL
Topic: PgSqlDump restore fails with Dump data's date format
Replies: 8
Views: 2019

Re: PgSqlDump restore fails with Dump data's date format

Coming rapidly to the conclusion that backup/restore using the methods for anything other than simple DB's doesn't work. Been trying this on an off for many versions. Yet to have a satisfactory result.

doing it via pg_dump/restore is a bigger security hole though.

Mmmmmm
by kerrywales
Thu 29 Nov 2012 22:21
Forum: dotConnect for PostgreSQL
Topic: PgSqlDump restore fails with Dump data's date format
Replies: 8
Views: 2019

Re: PgSqlDump restore fails with Dump data's date format

Continuing my saga to try and work out the options to make backup and restore work (given that the test of a more complex db takes 2 hours) I have found a combination that creates the tables and constraints.

The backup object code is set to:
ObjectTypes = PgSqlDumpObjects.All ^ PgSqlDumpObjects.Users ^ PgSqlDumpObjects.Languages
Mode = DumpMode.All

This seems to work till the end. It fails starting with:

Code: Select all

2012-11-29 21:47:28 GMT	ERROR	syntax error at or near "" PRIMARY KEY ("" at character 104237	
2012-11-29 21:47:28 GMT	STATEMENT	CREATE OR REPLACE FUNCTION "public"."dblink"( text, text)	
			  RETURNS SETOF record AS	
			$BODY$dblink_record$BODY$	
			  LANGUAGE 'c';	


Do I need to back up the dblink info. If not how do I say don't back it up

The text follows with setting defaults then views. I appears to try and run this section of script in one go.

Any advice if anyone has got the mechanism working correctly greatfully received.
by kerrywales
Thu 29 Nov 2012 13:42
Forum: dotConnect for PostgreSQL
Topic: PgSqlDump restore fails with Dump data's date format
Replies: 8
Views: 2019

Re: PgSqlDump restore fails with Dump data's date format

Removing the CREATE USER lines does allow the restore method to function except::::

either the restore method calculates the length before srtipping out special characters or the dump method is adding characters to the string.

I am finding that dumped strings close'ish to the limit of of the character varying field is erroring on restore with PG complaining that the string is too long.

e.g. a table containing multiline text which the db says has 441 chars in it (size is set to 470) reckons that the restore value has over 500. So it stops!!

I don't know if it is the dump or the restore.
by kerrywales
Mon 26 Nov 2012 11:59
Forum: dotConnect for PostgreSQL
Topic: PgSqlDump restore fails with Dump data's date format
Replies: 8
Views: 2019

PgSqlDump restore fails with Dump data's date format

Hi all,
I am using dotConnect to PostgreSQL 6.2.77.0

I have a pgsqldump routine to create a backup file and I am testing the file by restoring it.

When using

Code: Select all

DataRestore.Restore(RestoreString);
it fails with a date /time error.
date/time field value out of range: \"31/12/9999\"
I think this is from one of the earlies lines
CREATE USER **** WITH SYSID 16395 PASSWORD '****' CREATEDB CREATEUSER VALID UNTIL '31/12/9999';
If the dump function created this line why cannot the restore function restore with it?
I am presuming it is because the pg wants it in yyyy-mm-dd format.

A quick search in the 1Gb text file produced by the dump function shows that most data is in the american format.

dunmp uses the basic code:

Code: Select all

  var myConnection = new CSLConnect(UserName, Password, Port, HostName, DBName);
  if (myConnection.Login())
  {
    using (var dataBackup = new PgSqlDump()
    {
      Connection = myConnection.getConnection(),
      IncludeBlob = true,
      ObjectTypes = PgSqlDumpObjects.All,
      GenerateHeader = true,
      Mode = DumpMode.All
    })
    {
      dataBackup.Backup(Path.Combine(Destination, BackupName + ".backup"));
    }
    myConnection.Logout();
}
Regards
by kerrywales
Mon 19 Mar 2012 19:44
Forum: dotConnect for PostgreSQL
Topic: complex query works in 5.50.237 but not from 5.70.311
Replies: 7
Views: 1645

I have now managed an installation of 5.50. This now correctly processes the query.

I hope you can resolve the issue in 5.70/5.80 soon.

Regards
by kerrywales
Wed 14 Mar 2012 12:27
Forum: dotConnect for PostgreSQL
Topic: complex query works in 5.50.237 but not from 5.70.311
Replies: 7
Views: 1645

Followed your instructions. Got error dialog boxes whilst installing older version.

Modules which are not in the manifest were streamed in (Exception from HRESULT: 0x80131043)
Please contact Devart support team

The Install.log is as follows
--- Custom action error: CrGacUtil
Date: 14/03/2012 12:24:01
Environment
Operating System: Microsoft Windows NT 6.0.6002 Service Pack 2
.NET Framework: 2.0.50727.4216
Assembly: CrGacUtil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=09af7300eec23701
Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)
CustomMessage: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Inner Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)

--- Custom action error: CrGacUtil
Date: 14/03/2012 12:25:27
Environment
Operating System: Microsoft Windows NT 6.0.6002 Service Pack 2
.NET Framework: 2.0.50727.4216
Assembly: CrGacUtil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=09af7300eec23701
Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)
CustomMessage: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Inner Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)

--- Custom action error: CrGacUtil
Date: 14/03/2012 12:25:30
Environment
Operating System: Microsoft Windows NT 6.0.6002 Service Pack 2
.NET Framework: 2.0.50727.4216
Assembly: CrGacUtil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=09af7300eec23701
Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)
CustomMessage: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Inner Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)

--- Custom action error: CrGacUtil
Date: 14/03/2012 12:25:32
Environment
Operating System: Microsoft Windows NT 6.0.6002 Service Pack 2
.NET Framework: 2.0.50727.4216
Assembly: CrGacUtil, Version=1.0.0.0, Culture=neutral, PublicKeyToken=09af7300eec23701
Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)
CustomMessage: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Inner Exception
Message: Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)
Type: Devart.Common.Setup.CustomActionException
StackTrace: at CrGacUtil.Program.Main(String[] args)
by kerrywales
Wed 14 Mar 2012 11:26
Forum: dotConnect for PostgreSQL
Topic: complex query works in 5.50.237 but not from 5.70.311
Replies: 7
Views: 1645

Thank you. I will try the removal. I now know one of my colleagues has already reported the issue to you and is awaiting a reply on another thread.

Regards
by kerrywales
Sat 10 Mar 2012 09:52
Forum: dotConnect for PostgreSQL
Topic: complex query works in 5.50.237 but not from 5.70.311
Replies: 7
Views: 1645

complex query works in 5.50.237 but not from 5.70.311

I have a query from a single table but lots of "let" statements similar to

var CalcQuery = from Branch in entity.Branch
.....
select new
{
....
}

foreach (var Branch in CalcQuery)
{
....
}


let varVatTotals = Branch.TblJobHeads.Sum(o => o.TblAccounts.VAT != null ? o.TblAccounts.VAT: 0M)

This is followed by a foreach to process each record. When starting the


This worked fine with

5.50.237

I have just updated to 5.70.311. Same code that worked now produces an error

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> Devart.Data.PostgreSql.PgSqlException: column Project8.C2 does not exist

The error refers to an internally created column, not one of mine.

I have tried to uninstall 5.70 to go back to 5.50. This is causing problems when 5.50 installs. So I have two issues.

1. Anyone else seen a similar issue and can guide me to a work around?
2. Should I need to do something when uninstalling 5.70 to reinstall 5.50 because using the standard uninstall/install is failing.

My dev PC is Vista 32 bit.
by kerrywales
Tue 25 Oct 2011 12:30
Forum: dotConnect for PostgreSQL
Topic: app.config runtime section for apps
Replies: 1
Views: 1175

app.config runtime section for apps

From v4 with vs 2008 to provide a distributed version of the application I provide the needed DLL's in the same folder of the app and I have the following lines in the app.config

This first one is fine and the version number is changed with every update

Code: Select all

		
			
			
		
	
However I had the need to add the following section

Code: Select all

		
			
				
				
			
		
	
which I have never changed and the distributed app seems happy and I don't need to install the client files from the Devart .exe.

But Devart has been updated many times since the code was first written and VS2010 now shows Devart.Data to be of version
5.0.327.0

I must have the runtime section in the app.config or the app wont run. But the config has, in my eyes, a wrong version number. Yet it happily works.

My questions are:
Why so I need the section if it is ignored?
Should I be matching the upper version limit with the version number shown in the VS properties box for Devart.Data?

Thanks.
by kerrywales
Sun 25 Sep 2011 08:53
Forum: dotConnect for PostgreSQL
Topic: How do you Drop a database after testing it does not exist
Replies: 1
Views: 1008

How do you Drop a database after testing it does not exist

I am trying to write code that:
1. Tests if a DB Exists
2. If the DB exists then offer the option for the user to drop the database, and if "Yes" Drop the Db.

I test using

Code: Select all

try
{using (PgSqlConnection conn = new PgSqlConnection())
                    {
                        conn.ConnectionString = string.Format("... ...",
                            teDestinationHost.Text, teDestinationPort.Text, teDestinationDatabase.Text);
                        conn.Open();
                        conn.Close();
                        DbExists = true;
                    }
} ...

if (DbExists)
                    {
                        ...
using (PgSqlConnection conn = new PgSqlConnection())
            {
                conn.ConnectionString = string.Format("... ...",
                    teDestinationHost.Text, teDestinationPort.Text);
                conn.Open();
                string cmdstring = "DROP DATABASE IF EXISTS \"" + teDestinationDatabase.Text.Trim() + "\";";

                PgSqlCommand cmd = new PgSqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                cmd.CommandText = cmdstring;
                try
                {
                    cmd.ExecuteNonQuery();
                    result = true;
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Failed to drop Database\n"+ex.Message);
                };
            }
It never drops the database. The error says someone is using it. The only "using" of the DB is in the connection to test it exists.

I have obviously misunderstood the constructs and even though I close the connection pg still thinks it is active.

Can anyone give me an alternative approach.

Thanks
by kerrywales
Sun 25 Sep 2011 08:32
Forum: dotConnect for PostgreSQL
Topic: Running sql script produced by pg_dump 9.1. Is it possible?
Replies: 2
Views: 1259

Looking on the forum I came across some code and adapted it. This creates the DB. There are errors which are ignored in this code

Code: Select all

StreamReader streamReader = new StreamReader("pgDumpScript.sql");
                    string text = streamReader.ReadToEnd();
                    streamReader.Close();
                    PgSqlScript cmdScript = new PgSqlScript(text, conn);
                    
                    foreach (SqlStatement pgStatement in cmdScript.Statements)
                    {
                        try
                        {
                            pgStatement.Execute();
                         }
                        catch
                        {
                            Console.WriteLine("  Failed");
                        }
                    } 
                    conn.Close();
,,