Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15463

does my database connection is closed properly?

$
0
0
Hi,

I am facing FATAL: sorry, too many clients already in postgresql-12.

I need advice about database connection, does my code below already close the database connection properly?

Code:

          try
          {
                using (NpgsqlConnection _conn = new NpgsqlConnection(Models.AppSettings.Application.PG_SQL.Connection_String))
                {
                    try
                    {
                        string _sql = "Select * From mytable";

                        var _dr = await _conn.ExecuteReaderAsync(_sql, new { });
                       
                        if (_dr.HasRows)
                        {
                            while (await _dr.ReadAsync())
                            {
                           
                            }
                        }

                    }
                    catch (Exception ex) { ..... }
                    finally { }
                }
            }
            catch (Exception ex) { .... }
            finally { }


Viewing all articles
Browse latest Browse all 15463

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>