Thread: How to improve PgSql Performance using npgsql

How to improve PgSql Performance using npgsql

From
"Venkat Rao Tammineni"
Date:
<div class="Section1"><p class="MsoNormal"><span style="font-family:"Courier New";color:#4F81BD">Dear All,</span><p
class="MsoNormal"><spanstyle="font-family:"Courier New";color:#4F81BD"> </span><p class="MsoNormal"><span
style="font-family:"CourierNew";color:#4F81BD">  I am using   npgsql.dll to connect  postgresql database. Everything is
workingfine.but sometimes database is getting slow and even sometimes I am not getting data .I have written one
functionwhich access the data .</span><p class="MsoNormal"><span style="font-family:"Courier
New";color:#4F81BD"> </span><pclass="MsoNormal"><span style="font-family:"Courier New";color:#4F81BD">Below is my code
..</span><pclass="MsoNormal"> <p class="MsoNormal" style="text-indent:.5in;text-autospace:none"><span
style="font-size:10.0pt;font-family:"CourierNew";color:blue"> public</span><span
style="font-size:10.0pt;font-family:"CourierNew"">  <span style="color:teal">NpgsqlConnection</span>
PgSqlDataConnection()</span><pclass="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; 
font-family:"Courier New"">        {</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">            <span style="color:blue">if</span> (pgSqlConnection != <span
style="color:blue">null</span>)</span><pclass="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; 
font-family:"Courier New"">            {</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">                <span style="color:blue">if</span> (pgSqlConnection.State == <span
style="color:teal">ConnectionState</span>.Open)</span><pclass="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">                {</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">                    pgSqlConnection.Close();</span><p class="MsoNormal"
style="text-autospace:none"><spanstyle="font-size:10.0pt; 
font-family:"Courier New"">                    <span style="color:green">//pgSqlConnection.Dispose();</span></span><p
class="MsoNormal"style="text-autospace:none"><span style="font-size:10.0pt; 
font-family:"Courier New"">                }</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">            }</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">            pgConnectionString = <span
style="color:teal">ConfigurationSettings</span>.AppSettings[<span
style="color:maroon">"ConnectionString"</span>].ToString();</span><pclass="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">            pgSqlConnection = <span style="color:blue">new</span> <span
style="color:teal">NpgsqlConnection</span>(pgConnectionString);</span><pclass="MsoNormal"
style="text-autospace:none"><spanstyle="font-size:10.0pt; 
font-family:"Courier New"">            <span style="color:blue">try</span></span><p class="MsoNormal"
style="text-autospace:none"><spanstyle="font-size:10.0pt; 
font-family:"Courier New"">            {</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">                pgSqlConnection.Open();</span><p class="MsoNormal"
style="text-autospace:none"><spanstyle="font-size:10.0pt; 
font-family:"Courier New"">            }</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">            <span style="color:blue">catch</span> (<span style="color:teal">Exception</span>
exp)</span><pclass="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt; 
font-family:"Courier New"">            {}</span><p class="MsoNormal" style="text-autospace:none"><span
style="font-size:10.0pt;
font-family:"Courier New"">            <span style="color:blue">return</span> pgSqlConnection;</span><p
class="MsoNormal"style="text-autospace:none"><span style="font-size:10.0pt; 
font-family:"Courier New"">       }</span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier
New"">      </span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"; 
color:#4F81BD">Please let me where I am doing wrong.</span><p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"CourierNew"; 
color:#4F81BD"> </span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";
color:#4F81BD">I am waiting for your great response.</span><p class="MsoNormal"><span
style="font-size:10.0pt;font-family:"CourierNew"; 
color:#4F81BD"> </span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";
color:#4F81BD">Advanced thanks.</span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";
color:#4F81BD"> </span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";
color:#4F81BD">Reagrds,</span><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";
color:#4F81BD">Venkat. </span><span style="color:#4F81BD"></span></div>

Re: How to improve PgSql Performance using npgsql

From
"Hilco Wijbenga"
Date:
2008/12/24 Venkat Rao Tammineni <vtammineni@roulacglobal.com>:
<snip/>
>             try
>             {
>                 pgSqlConnection.Open();
>             }
>             catch (Exception exp)
>             {}
<snip/>

I don't think you've really given enough information for anyone to
answer your question but at the very least you shouldn't just ignore
your exceptions. Maybe something fails but you'll never know.