How to avoid brakes when triggered try catch?

Good afternoon, dear colleagues.

There is a table with a bunch of records in which the field Subscriber presented in the form of a phone number and there is a mapping table of phone number to name(in field and FIO Subscriber). Salt in the fact that not all subscribers have refer name, in consequence of which definitely will drop exceptions(Exceptions) that I process and leave there just the phone number.

Retrieves from SQL like this:
SELECT TOP 100 Calls.ID Calls.DateTime Calls.Trunk Calls.Subscriber, Subscribers.FIO Calls.ExtNum, Calls.Duration, Calls.Direction, Calls.ExitCode FROM Calls LEFT OUTER JOIN Subscribers ON Calls.Subscriber = Subscribers.Subscriber ORDER BY ID DESC


Further reading:
while (reader.Read())
{
 rec = new CDRRecord();
 rec.ID = reader.GetInt64(0);
 rec.DateTime = reader.By the getdatetime(1);
 rec.Trunk = reader.GetString(2);

 //If the value of Subscribers.FIO is not Null, assigning it to the record 
 //if null - will be the Exception
try
{
 rec.Subscriber = reader.GetString(4);
}
 //then assign the value of recording Calls.Subscriber
catch
{
 rec.Subscriber = reader.GetString(3);
}

 rec.ExternalNumber = reader.GetString(5);
 rec.Duration = TimeSpan.FromTicks(reader.GetInt64(6));
 rec.Direction = reader.GetString(7);
 rec.ExitCode = reader.GetString(8);
records.Add(rec);

 }


This part works fine except for the fact that it is quite slow. If you do a sample of 100 records, then freezes for 1 second - not particularly critical, if 1000 can hang up to 5 seconds, and without the processing of the brakes will not, however, wish that there where there is information about the subscriber it was and where it should not show just the phone number.

The brake is inversely proportional to the amount of data in the table Subscribers, and that is logical — the more exceptions is invoked, the more brakes.

Please help or change the algorithm to avoid exceptions or to suggest how to avoid the brakes in this logic.

I understand that I'm doing something wrong, but that's where...

PS I tried to specify a specific exception in catch:
catch(SqlNullValueException)
no effect.
August 19th 19 at 23:44
4 answers
August 19th 19 at 23:46
Solution
Why do you not just exceptions, but in General the logic in the application? This elementary behavior is specified in the request.
SELECT TOP 100 Calls.ID Calls.DateTime Calls.Trunk 
coalesce(Subscribers.FIO Calls.Subscriber) as fieldname, ' if FIO is NULL, then use field value Subscriber
...
Thank you . Your decision best. Affected by the superficiality of my knowledge of SQL, anyway)) - alec30 commented on August 19th 19 at 23:49
August 19th 19 at 23:48
Before contacting call IDataRecord.IsDBNull (int) instead of checking with try-catch.
the difference in the placement of logic replacement - the database or application side. - alec30 commented on August 19th 19 at 23:54
It helped. Now I will look how it is implemented in its reply, and labeled the decision. - alec30 commented on August 19th 19 at 23:51
August 19th 19 at 23:50
It is not necessary to use exceptions to manage flow of program execution. Exception is expensive. Make a normal check instead.
August 19th 19 at 23:52
In my opinion there is with the sql query it would be necessary to change ideology

what prevents to wrap in isnull Subscribers.FIO and dump in this case id or something?

Find more questions by tags .NETC#Programming