Home All Groups Group Topic Archive Search About

database name in SqlException?

Author
2 Nov 2006 11:07 PM
bdgreen
Hi,

I searched around in SqlException, but couldn't find the name of the
database in question after catching a SqlException. It isn't
SqlException.Server, which has the database *server* name.  Anyone know
where I can find the database name?

Thanks in advance

Author
3 Nov 2006 7:28 AM
Miha Markic [MVP C#]
Don't you know which database you are connected to?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<bdgr***@pacbell.net> wrote in message
Show quote
news:1162508842.599881.268780@m73g2000cwd.googlegroups.com...
> Hi,
>
> I searched around in SqlException, but couldn't find the name of the
> database in question after catching a SqlException. It isn't
> SqlException.Server, which has the database *server* name.  Anyone know
> where I can find the database name?
>
> Thanks in advance
>
Author
3 Nov 2006 10:45 PM
bdgreen
Miha Markic [MVP C#] wrote:
> Don't you know which database you are connected to?
>

I'm writing something to look at numerous SqlExceptions across a large
codebase, from different areas of code.  So, the exceptions could be
happening on any number of different databases.
Author
4 Nov 2006 12:42 PM
Miha Markic [MVP C#]
Hi,

Ah, ok, I see. I couldn't find database name, either.
As a workaround you could wrap all calls to database in try/catch block (I
guess you have to already) and in catch block create your SqlException
derived exception that will hold additional database property.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<bdgr***@pacbell.net> wrote in message
Show quote
news:1162593925.960528.166840@m7g2000cwm.googlegroups.com...
> Miha Markic [MVP C#] wrote:
>> Don't you know which database you are connected to?
>>
>
> I'm writing something to look at numerous SqlExceptions across a large
> codebase, from different areas of code.  So, the exceptions could be
> happening on any number of different databases.
>
Author
4 Nov 2006 7:00 PM
bdgreen
Miha Markic [MVP C#] wrote:
> Hi,
>
> Ah, ok, I see. I couldn't find database name, either.
> As a workaround you could wrap all calls to database in try/catch block (I
> guess you have to already) and in catch block create your SqlException
> derived exception that will hold additional database property.

There's a wrapper with database name now, I just thought I'd check if
it's somewhere in SqlException, in case someone bypasses the wrapper.
But, if it isn't in there, it isn't in there ;)  Thanks for checking,
and for the replies.

AddThis Social Bookmark Button