<p>I'm looking at working on a project which uses C#.NET (sitting on a windows box) as the primary language and PostgreSQL as the backend database (backend is sitting on a linux box).  I've heard that ODBC.NET allows for easy integration of these two components.  </p>

<p>Has anyone had experience actually setting C# and PostgreSQL up to work together?  If so, do you have any suggestions about how to go about it, issues you've found, etc.?</p>

[{'answer_id': 47084, 'author': 'jalcom', 'author_id': 4463, 'author_profile': 'https://Stackoverflow.com/users/4463', 'pm_score': 7, 'selected': True, 'text': '<p>I\'m working with C# and Postgres using <b>Npgsql2</b> component, and they work fast, I recommend you.</p>\n\n<p>You can download from <a href="https://github.com/npgsql/Npgsql/releases" rel="noreferrer">https://github.com/npgsql/Npgsql/releases</a></p>\n\n<p><b>Note:</b> If you want an application that works with any database you can use the <b>DbProviderFactory</b> class and make your queries using <b>IDbConnection</b>, <b>IDbCommand</b>, <b>IDataReader</b> and/or <b>IDbTransaction</b> interfaces.</p>\n'}, {'answer_id': 47113, 'author': 'Andrei Rînea', 'author_id': 1796, 'author_profile': 'https://Stackoverflow.com/users/1796', 'pm_score': 2, 'selected': False, 'text': "<p>Today most languages/platforms (Java, .NET, PHP, Perl etc.) can work with almost any DBMS (SQL Server, Firebird, MySQL, Oracle, PostgresSQL etc.) so I wouldn't worry for one second. Sure there might be glitches and small problems but no showstopper.</p>\n\n<p>As jalcom suggested you should program against a set of interfaces or at least a set of base classes (DbConnection, DbCommand and so on) to have an easily adaptable application.</p>\n"}, {'answer_id': 47117, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 2, 'selected': False, 'text': "<p>You shouldn't have too many problems.  As others have mentioned, there's many .Net PostgreSQL data providers available.  One thing you may want to look out for is that features like Linq will probably not be able to be used.</p>\n"}, {'answer_id': 47602, 'author': 'David Schmitt', 'author_id': 4918, 'author_profile': 'https://Stackoverflow.com/users/4918', 'pm_score': 4, 'selected': False, 'text': '<p>There is a Linq provider for PostgreSQL at <a href="https://www.nuget.org/packages/linq2db.PostgreSQL/" rel="nofollow noreferrer">https://www.nuget.org/packages/linq2db.PostgreSQL/</a>.</p>\n'}, {'answer_id': 51703, 'author': 'Simon', 'author_id': 5385, 'author_profile': 'https://Stackoverflow.com/users/5385', 'pm_score': 2, 'selected': False, 'text': '<p>We have developed several applications using visual studio 2005 with the devart ado.net data provider for PostgreSql (<a href="http://www.devart.com/pgsqlnet/" rel="nofollow noreferrer">http://www.devart.com/pgsqlnet/</a>).</p>\n\n<p>One of the advantages of this provider is that it provides full Visual Studio support. The latest versions include all the new framework features like linq.</p>\n'}, {'answer_id': 9980601, 'author': 'Stradas', 'author_id': 5410, 'author_profile': 'https://Stackoverflow.com/users/5410', 'pm_score': 4, 'selected': False, 'text': '<p><strong>Npgsql</strong> - .Net Provider for PostGreSQL - is an excellent driver.  If you have used the more traditional ADO.NET framework you are really in luck here.  I have code that connects to Oracle that looks almost identical to the PostGreSQL connections.  Easier to transition off of Oracle and reuse brain cells.</p>\n\n<p>It supports all of the standard things you would want to do with calling SQL, but it also supports calling <strong>Functions</strong> (stored procedures).  This includes the returning of <strong>reference cursors</strong>.  The documentation is well written and provides useful examples without getting philosophical or arcane. Steal the code right out of the documentation and it will work instantly.  </p>\n\n<p>Francisco Figueiredo, Jr\'s and team have done a great job with this.<br>\nIt is now available on <strong>Github</strong>.<br>\n<a href="https://github.com/franciscojunior/Npgsql2" rel="noreferrer">https://github.com/franciscojunior/Npgsql2</a></p>\n\n<p>The better site for info is:\n<a href="http://npgsql.projects.postgresql.org/" rel="noreferrer">http://npgsql.projects.postgresql.org/</a></p>\n\n<p>Read the documentation! \n<a href="http://npgsql.projects.postgresql.org/docs/manual/UserManual.html" rel="noreferrer">http://npgsql.projects.postgresql.org/docs/manual/UserManual.html</a></p>\n'}, {'answer_id': 19038634, 'author': 'user542319', 'author_id': 542319, 'author_profile': 'https://Stackoverflow.com/users/542319', 'pm_score': 2, 'selected': False, 'text': '<p>Dont let a lack of Linq support stop you.  A pattern I use is to always return my data into lists, and then linq away.  I started doing this religiously when I found that the same (admittedly obscure) Linq expression in MySQL didnt bring back the same data as it did in Sql Server. </p>\n'}, {'answer_id': 40882625, 'author': 'JRA', 'author_id': 6711884, 'author_profile': 'https://Stackoverflow.com/users/6711884', 'pm_score': 1, 'selected': False, 'text': '<p>Just Go to Tool-->NuGet Package Manager-->Manager Nuget Package Manager</p>\n\n<p>search for <strong>NpgSql</strong> and then select your project and click Install</p>\n\n<p><strong>sample Code</strong></p>\n\n<pre><code>public void Demo()\n        {\n            NpgsqlConnection connection = new NpgsqlConnection();\n            connection = d_connection; // your connection string\n            connection.Open();              \n            NpgsqlCommand cmd = new NpgsqlCommand();\n            try\n            {\n                cmd.Connection = connection;\n                cmd.CommandText = "select * from your table name";\n                cmd.CommandType = System.Data.CommandType.Text;\n                using (var dataReader = cmd.ExecuteReader())\n                {\n                    while (dataReader.Read())\n                    {\n\n                     string answer= dataReader.IsDBNull(0) ? "" : dataReader.GetString(0);\n\n                    }\n                    dataReader.Dispose();\n                }\n            }\n            catch (Exception e)\n            {\n            }\n            finally\n            {\n                cmd.Dispose();\n                connection.Dispose();\n            }            \n        }\n</code></pre>\n\n<p>Dont use upper case in postgreSql because its case sensitive.</p>\n'}, {'answer_id': 55974221, 'author': 'Maciej', 'author_id': 77273, 'author_profile': 'https://Stackoverflow.com/users/77273', 'pm_score': 0, 'selected': False, 'text': '<p>Npgsql is excellent driver, but only issue Ive found so far is that Numeric value does not fit in a System.Decimal, so only option is correct each query or DB schema  </p>\n\n<p><a href="https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438#issuecomment-486586272" rel="nofollow noreferrer">https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438#issuecomment-486586272</a></p>\n'}]
['https://Stackoverflow.com/questions/47003', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/145/']