Thread: Re: Can PostgreSQL be used with ASP or .NET?

Re: Can PostgreSQL be used with ASP or .NET?

From
aaasssxxx@hotmail.com (aaasssxxx)
Date:
"Chad Chenoweth" <cchenowe@mines.edu> wrote in message news:<wDz78.19391$ym3.63838@rwcrnsc51.ops.asp.att.net>...
> I've been able to get postgreSQL to work with regular ASP, but have had no
> success getting it to work with ASP .Net.  The way I got it to work in
> regular ASP was to first create an ODBC connection to the database.  Then
> you can use the recordset and the connection objects.  For example, I've
> created an ODBC connection to my database and called it 'ODBC_PostgreSQL'.

do you use DSN or DSN-less?
I think that I am confusion on connect string for DSN-less,
anyone has ideas?

> This connection points to a database that has a single table called
> 'tblTest'.  In order to print the data from that table, use the following
> code:
>
> <%
>     dim conn        ' connection object
>     dim rst            ' recordset object
>     set conn = server.createobject("ADOdb.connection")
>     set rst = server.createobject("ADOdb.recordset")
>     conn.open "ODBC_PostgreSQL"

what is ODBC_PostgreSQL would be?


>     rst.open "Select * from " & chr(34) "tblTest" & chr(34), conn         '
> need to put double
>
> ' quotes around the table name.
>     'you now have a recordset that contains all data from tblTest.
>     do until rst.eof
>         response.write rst.fields("FIELD_NAME") .......
>         rst.movenext
>     loop
> %>
>
> Hopefully this helps,
>
> -- Chad
>
> FYI: a good ASP website is www.asp101.com
>
>

Re: Can PostgreSQL be used with ASP or .NET?

From
rey4@columbia.edu (Russell Yanofsky)
Date:
> can you tell us how do you create the database object?

Here's an example of using postgres in C#. "site" is a system DSN that
is set up with a username and password.

using Microsoft.Data.Odbc;

...

OdbcConnection postgres;
postgres = new OdbcConnection("DSN=site");
postgres.Open();

OdbcCommand cmd = new OdbcCommand("SELECT language_id, name FROM
languages");
cmd.Connection = postgres;

OdbcDataReader reader = cmd.ExecuteReader();

while(reader.Read())
  Response.Write("<option value=" + reader.GetInt32(0) + ">"
    + reader.GetString(1) + "</option>\n");

reader.Close();
postgres.Close();
postgres = null;

To use ODBC in .NET you need the "ODBC .NET Data Provider" available
at

http://msdn.microsoft.com/downloads/sample.asp?url=/msdn-files/027/001/668/msdncompositedoc.xml