Search code examples
c++visual-studio-2017npgsql

How to install npgsql for c++ in Visual Studio 2017


sorry if this is too simple to be of help to most people.

This is the first time I have done anything remotely like this and it appears that my problem is too unadvanced to be covered in any documentation. I am trying to connect a c++ project in Visual Studio 2017 to a PostgreSQL database. Just to be clear, I know how to run pgAdmin/host databases, code in C++, and I think I could handle the npgsql syntax if I got it working. However, I've never used .NET (although 4.5 is on my computer).

Here's what I am doing:

I start an empty project for C++ in Visual Studio 2017.
I open nuget manager and search npgsql, but my project is pointing to native,v0.0 instead of a .NET framework.
So I target v4.5 in the .NET framework property, but that doesn't change anything.

Could someone please tell if what I am trying to do is possible?
Should I be using a different project other than empty project?
Does this need to be some kind of web application?

If it is possible I'd love any advice on how to do it.


Solution

  • If you are writing a native c++ program it is very unlikely you want to bring in a .net assembly. If you want to connect to a pg database I would suggest instead that you use the odbc driver (https://odbc.postgresql.org/) or perhaps there is some library available as part of PG, but using a .net assembly will require a great deal of unnecessary interop work.