0107.sdt-postgre  - 0107 sdt postgre - Connecting to #PostgreSQL via C#

As a planned expansion to the SQL client ( for iOS, – soon support for and Postgre will be added.

The back-end to the app is some C# middleware, and the code it uses to connect to Postgre is as follows;

private static DataTable ExecutePostgre(string strDataSource, string databaseName, string strUsername, string strPassword, string strSQL)
const string strDsnTemplate = @”Server={0};User Id={1}; Password={2};Database={3};”;
var sqlConnection = string.Format(strDsnTemplate, strDataSource, strUsername, strPassword, databaseName);
var adapter = new NpgsqlDataAdapter(strSQL, sqlConnection) { SelectCommand = { CommandTimeout = 0 } };
var dataSet = new DataSet();
adapter.Fill(dataSet, “sql”);
return dataSet.Tables[“sql”];

Where NpgsqlDataAdapter comes from the Nuget Package Npgsql, which is installed using

Install-Package Npgsql

-  - Connecting to #PostgreSQL via C# - b - Connecting to #PostgreSQL via C#

Source link

No tags for this post.


Please enter your comment!
Please enter your name here