Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: The SOAP server requests the MSSQL database excute twice


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


Permlink Replies: 0
xiao yong zhang

Posts: 1
Registered: 1/11/18
The SOAP server requests the MSSQL database excute twice  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 1:34 AM
Soap Server links the MSSQL database, Soap Client access server once, but the soap server executes twice in the database.
use delphi 10.2 mssql 2014

1、DB Code:
CREATE TABLE [dbo].[testNewNo](
[ID] [BIGINT] IDENTITY(1,1) NOT NULL,
[NewNo] [INT] NULL,
[AskChar] [VARCHAR](50) NULL,
[BuildTime] [DATETIME] NULL,
CONSTRAINT [PK_testNewNo] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

create PROCEDURE [dbo].[P_New_No]
-- Add the parameters for the stored procedure here
@sAskChar VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @iNewNo int
SELECT @iNewNo=ISNULL(MAX(NewNo),0)+1
FROM [dbo].[testNewNo]
INSERT INTO [dbo].[testNewNo]
([NewNo]
,[AskChar]
,[BuildTime])
VALUES
(@iNewNo
,@sAskChar
,SYSDATETIME())
SELECT @iNewNo AS NewNo
END

2、Soap Server code:
2.1、use component:
SQLConnectionTest: TSQLConnection;
qr_Query_List: TSQLQuery;
dsp_Query_List: TDataSetProvider;

2.2、use interface
IDMTest = interface(IAppServerSOAP)

2.3、create function:
function TDMTest.funFindData(sSql: String): OleVariant;
begin
if qr_Query_List.Active then
qr_Query_List.Close;
qr_Query_List.sql.Text := sSql;
qr_Query_List.Open;
Result := dsp_Query_List.Data;
if qr_Query_List.Active then
qr_Query_List.Close;
end;

3、Client code:
3.1、use component:
SoapConnectionTest: TSoapConnection;
cdsFind: TClientDataSet;
dsResult: TDataSource;
edtGetUser: TEdit;
edtNewNo: TDBEdit;
3.2、 function code:
function funFindData(AsSql: String): OleVariant;
var
ITemp: IDMTest;
begin
if cdsFind.Active then
cdsFind.Close;
try
ITemp := (SoapConnectionTest.GetSOAPServer as IDMTest);
Result := ITemp.funFindData(AsSql);
cdsFind.Data := Result;
ITemp := nil;
except
on e: Exception do
begin
ITemp := nil;
raise Exception.Create('连接服务器失败,请重新登录!' + e.Message);
end
end;

end;

3.3、button code:
cdsFind.Data := funFindData('EXEC P_New_No ''' +
trim(edtGetUser.Text) + '''');
showMessage(cdsFind.fields[0].asinteger;

4、question :
first click button,result =1,but db table result insert two records,
click button result =3,but db table result insert other two records, result is four records

点两次按钮事件,结果应该是2,而不是3,数据应该是两条记录,不应该是4条记录
Point two button events, the result should be 2, not 3, the data should be 2 records, not 4 records.

5、All code files:
RSP-19511

Edited by: xiao yong zhang on Dec 11, 2017 1:50 AM

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02