Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005

    Unanswered: Connecting and retrieving data from postgresql database

    I'm a bit confused about the best way to connect to a database server
    from .net. Basically I have a Linux machine running the PostgreSQL
    database server which I routinely connect to from Windows 2000 Server,
    via ODBC, using a database admin tool.

    I need to access and modify the contents of tables on my PostgreSQL
    database from .net in C#. There seem to be a lot of ways of doing this
    and I don't know the difference between them nor which is the best way
    for my purposes. Should I use ADO, OLEDB? Can I achieve what I want just
    using the SqlConnection and SqlCommand classes? Do I need to download
    and install Oracle.NET and what is the relevance of the
    System.Data.Odbc.dll file?

    With MFC (Microsoft Foundation Class) things were a lot simpler, I used
    the CDatabase and CRecordset classes; you connected using ODBC with
    CDatabase and used CRecordset to manage your sql queries/commands. Is
    there a similar pair of classes in .net?

    Many thanks for your help, as you can see I am a bit unsure of my ground


  2. #2
    Join Date
    Feb 2005

    I use ADO.NET components provided by Core Labs.
    Try their trial product.

    Here how to connect to postgree :
    CoreLab.PostgreSql.PgSqlConnection pgSqlConnection ;
    pgSqlConnection = new CoreLab.PostgreSql.PgSqlConnection();
    pgSqlConnection.ConnectionString = "User Id=<Pg database username >;Password=<pass was here>;Host=<host address>;Database=<Pg database name>";

    Here is one way to get records from the database using Data adaptor:

    public DataTable ExecuteQuery(string cmdText)
    adapter=new CoreLab.PostgreSql.PgSqlDataAdapter(cmdText,pgSqlC onnection);
    DataTable data = new DataTable();
    return data;

  3. #3
    Join Date
    Feb 2005
    Belgium, Flanders

    Cool bad experience with odbc in java

    I know, java isn't .net.
    still, odbc had a very strange way of handling my connections,
    I gave up.
    I also use a linux server for my postgresql db.

    I ended up finding drivers directly connecting to the server,
    kind of replacing odbc, but these were jar files (java) ofcourse.

    It can be a hint to look for other solutions instead of odbc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts