Revit 2022 Environment Preventing SSL handshake with PostgreSQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to connect an Azure PostgreSQL DB to Revit via the API and I am running into a very frustrating situation and was hoping someone may have the experience I need to at least know why its failing so I can try to resolve it.
I have successfully used MySQL and MSSQL in the past without any issues, but for some reason within the Revit context I am getting and SSL error. I know this may not be a direct Revit API question, BUT a desktop application with the EXACT same executing code works flawlessly. So, this make me think there is something (maybe a reference) that is got me caught up here and that is why I am grasping here a bit hoping to get lucky.
Code is very straight forward at this point just to test the connection.
1. External Application with a single button that using an external command to call another dll (separated them for multi app support).
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RDG_Revit_2022.Testing
{
[Transaction(TransactionMode.Manual)]
class Test : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
Document doc = uiapp.ActiveUIDocument.Document;
//This is the external reference call
pgRDG.Connection.Testing();
return Result.Succeeded;
}
}
}
2. Here is the code within the Testing() method
using System;
using System.Windows;
using Npgsql;
namespace pgRDG
{
public class Connection
{
public static void Testing()
{
string ConnString = "Server=name.postgres.database.azure.com;Database=dbName;Port=5432;User Id=Username;Password=Password;Trust Server Certificate=true;Ssl Mode=Require";
using(NpgsqlConnection conn = new NpgsqlConnection(ConnString))
{
try
{
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM table", conn);
NpgsqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
MessageBox.Show(reader.GetString(reader.GetOrdinal("command")));
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
}
3. When I run the code I receive this error message.
Again, if I run that code in a desktop app it executes without any errors which is why I am posting here wondering if anyone could give me any hints as to what within the Revit environment may be causing this issue.
Also submitted a GitHub request for reference:
Specified SSL Protocol Type is not Valid · Issue #3718 · npgsql/npgsql (github.com)