Quantcast
Channel: Catch SqlException
Viewing all articles
Browse latest Browse all 5

Catch SqlException

$
0
0

Harry,

I think because you are opening the connection to SQL server outside (before) of the try-catch block.

The best way is like:

 using (SqlConnection connection = new SqlConnection(connectionString))
    {
        try
        {
            connection.Open();
            Execute a Get stored procedure to read data from a table
        }
        catch (SqlException)
        {
            log the exception
        }
    }
Hope it helps!!


Please click "Mark As Answer" if my post helped.


Viewing all articles
Browse latest Browse all 5

Trending Articles



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