Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Service Failing when connection to Sql Fails


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Mar 22, 2017 11:40 PM Last Post By: Coşkun Çınar Threads: [ Previous | Next ]
Donald Bossen

Posts: 81
Registered: 2/3/02
Service Failing when connection to Sql Fails  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2016 9:07 AM
I need to bullet prof my connection to my sql server here is my connection code.
try
ConnectionJBI.Connected := True;
if ConnectionJBI.Connected then
begin
result := True;
end
else
begin
result := False;
Msg := 'Unable to Connect to JBI Database Bad Ip or Connection Missing';
end;
except
result := False; // Exception fired in connecting to JBI
Msg := 'Unable to Connect to JBI Database Bad Ip or Connection Missing';
end
I need this code to raise no exception return false and continue on I am not sure how to eat the exception
Thanks In advance
Donald S. Bossen
Coşkun Çınar

Posts: 2
Registered: 4/17/17
Re: Service Failing when connection to Sql Fails  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 22, 2017 11:40 PM   in response to: Donald Bossen in response to: Donald Bossen
there are 2 ways
first :

raise Exception.Create('your error message');

second : I think this method is better

type
myresult = record
results :Boolean;
messages:string;

end;


procedure TForm1.Button1Click(Sender: TObject);
function baslan:myresult;
begin
try
ConnectionJBI.Connected := True;
if ConnectionJBI.Connected then
begin
Result.results:=True;
Result.messages:='connected';
end
else
begin
Result.results := False;
Result.messages:= 'not connected';
end;
except on e:Exception do
begin
Result.results := False;
Result.messages:= ' Error : ' + e.Message;
end
end;
end;
var
response :myresult;
begin
response:=baslan;
ShowMessage(BoolToStr(response.results));
ShowMessage(response.messages);
end;

Donald Bossen wrote:
I need to bullet prof my connection to my sql server here is my connection code.
try
ConnectionJBI.Connected := True;
if ConnectionJBI.Connected then
begin
result := True;
end
else
begin
result := False;
Msg := 'Unable to Connect to JBI Database Bad Ip or Connection Missing';
end;
except
result := False; // Exception fired in connecting to JBI
Msg := 'Unable to Connect to JBI Database Bad Ip or Connection Missing';
end
I need this code to raise no exception return false and continue on I am not sure how to eat the exception
Thanks In advance
Donald S. Bossen
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02