MySQL Forums
Forum List  »  Delphi

Stored procedure and parameter problem using odbc.net
Posted by: Andi Purwito
Date: November 07, 2007 03:38AM

Hi all..
Here's my code in delphi asp.net:

function TGolekUpo.AddOnlineUser(IPADDRESS, SESSIONID, USER_AGENT, REFERER: string; var ErrMsg: string): boolean;
var
kd: TKoneksiDB;
begin
kd := TKoneksiDB.Create;
with kd do
begin
try
myConnection := OdbcConnection.Create(ConfigurationSettings.AppSettings['conn_string']);
myConnection.Open;
myCommand := OdbcCommand.Create('sp_AddOnlineUser', myConnection);
myCommand.CommandType := CommandType.StoredProcedure;
myCommand.Parameters.Add('@IP', IPADDRESS);
myCommand.Parameters.Add('@SID', SESSIONID);
myCommand.Parameters.Add('@UA', USER_AGENT);
myCommand.Parameters.Add('@RF', REFERER);
myCommand.ExecuteNonQuery;
except on E: Exception do
ErrMsg := E.Message;
end;
myConnection.Close;
end;
end;

and here's my stored procedure:

DELIMITER $$

DROP PROCEDURE IF EXISTS `dbrkredit`.`sp_AddOnlineUser`$$
CREATE DEFINER=`sysdev`@`fw999.bankbna.net` PROCEDURE `dbrkredit`.`sp_AddOnlineUser`(IN IP CHAR(250),
IN SID CHAR(50),
IN UA CHAR(250),
IN RF CHAR(250))
BEGIN
INSERT INTO t_onlineuser(IPADDRESS, SESSIONID, USER_AGENT, REFERER)
VALUES (IP, SID, UA, RF);
END $$

DELIMITER ;

The problem is when i call this sp from my function above, it return an error below:

ERROR [42000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.22]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sp_AddOnlineUser' at line 1

However it was ok and data succesfuly inserted if i call from MySQL Query Browser using: Call sp_AddOnlineUser('value1','value2','value3','value4')

And then i change my function become:

function TGolekUpo.AddOnlineUser(IPADDRESS, SESSIONID, USER_AGENT, REFERER: string; var ErrMsg: string): boolean;
var
kd: TKoneksiDB;
begin
kd := TKoneksiDB.Create;
with kd do
begin
try
myConnection := OdbcConnection.Create(ConfigurationSettings.AppSettings['conn_string']);
myConnection.Open;
myCommand := OdbcCommand.Create('sp_AddOnlineUser', myConnection);
myCommand.CommandType := CommandType.StoredProcedure;
myCommand.Parameters.Add('?IP', IPADDRESS);
myCommand.Parameters.Add('?SID', SESSIONID);
myCommand.Parameters.Add('?UA', USER_AGENT);
myCommand.Parameters.Add('?RF', REFERER);
myCommand.ExecuteNonQuery;
except on E: Exception do
ErrMsg := E.Message;
end;
myConnection.Close;
end;
end;

Then there's no error occured but no data inserted.

I use Connector/ODBC version 3.51.21 and MySQL server version 5.0.22

then i change my function again become:

function TGolekUpo.AddOnlineUser(IPADDRESS, SESSIONID, USER_AGENT, REFERER: string; var ErrMsg: string): boolean;
var
kd: TKoneksiDB;
p1, p2, p3, p4: OdbcParameter;
begin
kd := TKoneksiDB.Create;
with kd do
begin
try
myConnection := OdbcConnection.Create(ConfigurationSettings.AppSettings['conn_string']);
myConnection.Open;
myCommand := OdbcCommand.Create('sp_AddOnlineUser', myConnection);
myCommand.CommandType := CommandType.StoredProcedure;
myConnection := OdbcConnection.Create(ConfigurationSettings.AppSettings['conn_string']);
myConnection.Open;
myCommand := OdbcCommand.Create('sp_AddOnlineUser', myConnection);
myCommand.CommandType := CommandType.StoredProcedure;

p1 := OdbcParameter.Create('@IP', OdbcType.VarChar, 15);
p1.Value := IPADDRESS;
p1.Direction := ParameterDirection.Input;
myCommand.Parameters.Add(p1);

p2 := OdbcParameter.Create('@SID', OdbcType.VarChar, 50);
p2.Value := SESSIONID;
p2.Direction := ParameterDirection.Input;
myCommand.Parameters.Add(p2);

p3 := OdbcParameter.Create('@UA', OdbcType.VarChar, 250);
p3.Value := USER_AGENT;
p3.Direction := ParameterDirection.Input;
myCommand.Parameters.Add(p3);

p4 := OdbcParameter.Create('@RF', OdbcType.VarChar, 250);
p4.Value := REFERER;
p4.Direction := ParameterDirection.Input;
myCommand.Parameters.Add(p4);

// myCommand.Parameters.Add('@IP', IPADDRESS);
// myCommand.Parameters.Add('@SID', SESSIONID);
// myCommand.Parameters.Add('@UA', USER_AGENT);
// myCommand.Parameters.Add('@RF', REFERER);
myCommand.ExecuteNonQuery;
except on E: Exception do
ErrMsg := 'AddOnlineUser: '+E.Message;
end;
myConnection.Close;
end;
end;

there's still no successfuly result, so if i change '@' with '?'.

Anyone can help me or found like this before?

Thanks & regards
Andi Purwito

Options: ReplyQuote


Subject
Written By
Posted
Stored procedure and parameter problem using odbc.net
November 07, 2007 03:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.