By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

C# .NET ===> postgreSQL

P: 2
I am creating a C# .NET application that uses a postgreSQL database that is on my machine locally. My problem is that I cannot figure out how to write the connectionString. I have searched the internet for the past 30 minutes trying everything I could find.

Help? anyone?


Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Connection
  3. {
  4.     protected static SqlConnection conn;
  5.     private const string connStr = "???";
  6.  
  7.     public static SqlConnection getConnection()
  8.     {
  9.         if(conn == null)
  10.         {
  11.             conn = new SqlConnection(connStr);
  12.             conn.Open();
  13.         }
  14.         return conn;
  15.     }
  16. }
  17.  
Mar 11 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 534
You probably want to look at the Postgres` Client Interfaces, especially libpq - C library and this Example Program
Mar 11 '07 #2

P: 3
I am creating a C# .NET application that uses a postgreSQL database that is on my machine locally. My problem is that I cannot figure out how to write the connectionString. I have searched the internet for the past 30 minutes trying everything I could find.

Help? anyone?


Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Connection
  3. {
  4.     protected static SqlConnection conn;
  5.     private const string connStr = "???";
  6.  
  7.     public static SqlConnection getConnection()
  8.     {
  9.         if(conn == null)
  10.         {
  11.             conn = new SqlConnection(connStr);
  12.             conn.Open();
  13.         }
  14.         return conn;
  15.     }
  16. }
  17.  
use odbc connection class.
you r using sqlconnection class.
Mar 20 '07 #3

P: 5
I am creating a C# .NET application that uses a postgreSQL database that is on my machine locally. My problem is that I cannot figure out how to write the connectionString. I have searched the internet for the past 30 minutes trying everything I could find.

Help? anyone?


Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Connection
  3. {
  4.     protected static SqlConnection conn;
  5.     private const string connStr = "???";
  6.  
  7.     public static SqlConnection getConnection()
  8.     {
  9.         if(conn == null)
  10.         {
  11.             conn = new SqlConnection(connStr);
  12.             conn.Open();
  13.         }
  14.         return conn;
  15.     }
  16. }
  17.  
Do you consider to use npgsql ?

with that you can connect to the database simply making this (example from the user manual):

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using Npgsql;
  4.  
  5. public class NpgsqlUserManual
  6. {
  7.   public static void Main(String[] args)
  8.   {
  9.     NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=joe;Password=secret;Database=joedata;");
  10.     conn.Open();
  11.     conn.Close();
  12.   }
  13. }
  14.  
Mar 31 '07 #4

Expert
P: 83
There's also an OLEDB interface to PostgreSQL:

http://pgfoundry.org/projects/oledb/

I'd think Npgsql should be more efficient if you care a lot about performance, though.
Apr 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.