0

I am currently working on an azure function that connects to a odbc driver. I have one locally called 'Dobbe WMS productie' and i am using the following code to connect to it.

using(odbcConnection conn = new OdbcConnection("DSN=Dobbe WMS productie"))
{
    conn.Open();
    // performs some actions
    conn.Close();
}

Locally this works just fine. Now I published this to azure and it is not working, as i expected. The problem is, I cant find anything to solve my issue. Is there anyone that can help me with this?

EDIT:
My full error message: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

I opened the ODBC-datasources on windows -> System-DSN -> add and then choose the postgresql ansi driver. Filled out the basics in the form and clicked on save

I have also tried Npgsl and got the following error: The remote certificate is invalid according to the validation procedure. my connection string looks something like this: Server=address;Port=5432;Database=dbname;User Id=username;Password=password;SslMode=Require

rene
  • 41,474
  • 78
  • 114
  • 152
  • `I cant find anything to solve my issue` did you deploy the driver? Did you create the data source? What error did you get? – Panagiotis Kanavos Jul 23 '21 at 14:00
  • Hello @PanagiotisKanavos , thanks for your quik response! I havent done anything such as deploying it. If you have a reference to some documentation I would really appreciate it. Also take a look at the edit – Danny Verdel Jul 23 '21 at 14:05
  • Well, did you read what the error says? How do you expect to connect to a data source that doesn't exist? `a reference to some documentation` how did you set up the data source on your machine? – Panagiotis Kanavos Jul 23 '21 at 14:05
  • @PanagiotisKanavos I know what it says. I expected an error like this because i have a driver local. But i dont know where to start to be able to access it from azure – Danny Verdel Jul 23 '21 at 14:07
  • @PanagiotisKanavos I opened the ODBC-datasources on windows -> System-DSN -> add and then choose the postgresql ansi driver. Filled out the basics in the form and clicked on save – Danny Verdel Jul 23 '21 at 14:10
  • I'm curious. Where will that postgresql database be when you have deployed your azure function in Azure? – rene Jul 23 '21 at 14:17
  • @rene, the postgresql database is a cloud database. But I dont own it. We got instructions from another company to connect to it – Danny Verdel Jul 23 '21 at 14:19
  • Shouldn't you use the native .net driver: https://www.npgsql.org/ instead of Odbc? That at least reduces your deployment dependencies a bit. – rene Jul 23 '21 at 14:19
  • @rene I have tried this to. Please take a look at the edit – Danny Verdel Jul 23 '21 at 14:24
  • I highly doubt you will ever be able to use an ODBC driver in an Azure function. ODBC drivers require an local installation step that I doubt is feasible within an azure function, given how those get packaged, deployed and managed. You not only need the ODBC components but also the native bridge. – rene Jul 23 '21 at 14:26
  • the remote certificate issue is solvable by adding a custom cert validation on the servicepoint manager. Assuming you have an unwilling server administrator to properly configure cetifiicates on their end. – rene Jul 23 '21 at 14:28
  • @rene Do you have any examples of this? Thanks in advance – Danny Verdel Jul 23 '21 at 14:30
  • 1
    https://stackoverflow.com/questions/42712844/ignore-bad-certificate-net-core and more on https://stackoverflow.com/search?q=%5Bc%23%5D+servicepointmanager+certificate+is%3Aq+answers%3A1 – rene Jul 23 '21 at 14:33

1 Answers1

0

Thanks to the help of @rene I managed to get this working with NpgSQL. After some digging into service point manager I found out I had to do one small thing. Which is modifying the connection string to something like this:

Server=address;Port=5432;Database=dbname;User Id=username;Password=password;SslMode=Require;Trust Server Certificate=true