Avatar of Ron Kidd
Ron KiddFlag for Australia

asked on 

Include SQL String in SQL Exception

Hello

I have a 3 tier application in VB.net 2015

Is there anyway to include the SQL String in an SQL Exception?

In the Data Access Layer I have a function
    Shared Function GetNames() As System.Data.Common.DbDataReader

        Dim sqlString As String

        'sqlString = "select seqno,description from NoSuchTable"
        Using cmd As New SqlCommand(sqlString, Sql.ConnSQL)

            Try
                Return cmd.ExecuteReader(CommandBehavior.CloseConnection)

            Catch ex As Exception

                Throw
            End Try

        End Using   'cmd
    End Function

Open in new window


This causes an exception to be raised that is Logged at the Calling BLL Level.
What I need is some way to also send the SQL String that caused the Exception (The Local Variable sqlString) with the exception so it can also be recorded.
Visual Basic.NETMicrosoft SQL Server.NET Programming

Avatar of undefined
Last Comment
Ron Kidd
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ron Kidd
Ron Kidd
Flag of Australia image

ASKER

Thanks James

I'd just worked it out and saw the rest of your example when I went to accept the Answer.
Thanks again.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo