C# .NET ===> postgreSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smurphy811
    New Member
    • Mar 2007
    • 2

    #1

    C# .NET ===> postgreSQL

    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 connectionStrin g. I have searched the internet for the past 30 minutes trying everything I could find.

    Help? anyone?


    Code:
    	
    public class Connection
    {
    	protected static SqlConnection conn;
    	private const string connStr = "???";
    	
    	public static SqlConnection getConnection()
    	{
    		if(conn == null)
    		{
    			conn = new SqlConnection(connStr);
    			conn.Open();
    		}
    		return conn;
    	}
    }
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    You probably want to look at the Postgres` Client Interfaces, especially libpq - C library and this Example Program

    Comment

    • knowledgeseeker
      New Member
      • Feb 2007
      • 3

      #3
      Originally posted by smurphy811
      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 connectionStrin g. I have searched the internet for the past 30 minutes trying everything I could find.

      Help? anyone?


      Code:
      	
      public class Connection
      {
      	protected static SqlConnection conn;
      	private const string connStr = "???";
      	
      	public static SqlConnection getConnection()
      	{
      		if(conn == null)
      		{
      			conn = new SqlConnection(connStr);
      			conn.Open();
      		}
      		return conn;
      	}
      }
      use odbc connection class.
      you r using sqlconnection class.

      Comment

      • agasca
        New Member
        • Mar 2007
        • 5

        #4
        Originally posted by smurphy811
        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 connectionStrin g. I have searched the internet for the past 30 minutes trying everything I could find.

        Help? anyone?


        Code:
        	
        public class Connection
        {
        	protected static SqlConnection conn;
        	private const string connStr = "???";
        	
        	public static SqlConnection getConnection()
        	{
        		if(conn == null)
        		{
        			conn = new SqlConnection(connStr);
        			conn.Open();
        		}
        		return conn;
        	}
        }
        Do you consider to use npgsql ?

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

        Code:
        using System;
        using System.Data;
        using Npgsql;
        
        public class NpgsqlUserManual
        {
          public static void Main(String[] args)
          {
            NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=joe;Password=secret;Database=joedata;");
            conn.Open();
            conn.Close();
          }
        }

        Comment

        • nmadct
          Recognized Expert New Member
          • Jan 2007
          • 83

          #5
          There's also an OLEDB interface to PostgreSQL:



          I'd think Npgsql should be more efficient if you care a lot about performance, though.

          Comment

          Working...