Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 12th, 2003, 11:56 AM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
Question FireBird 1.5 RC3 and Stored Procedures w/ FireBird.Net Data provider

Giving my firsteps in FireBird I got stuck with an error when I tried to call a stored procedure. I don't know if the error is in the stored procedure or in th C# code.

Procedure:

Code:
CREATE PROCEDURE ADD_CLIENTE (
    NAME VARCHAR(255),
    EMAIL VARCHAR(75),
    ACTIVATED CHAR(1))
AS
begin
  BEGIN
INSERT INTO CLIENTES (NAME,EMAIL,ACTIVATED)
VALUES (:NAME, :EMAIL,:ACTIVATED);
END
  suspend;
end


C# Code:

Code:
FbConnection fb = new FbConnection(myConnectionString);
Fb.Open();
FbTransaction ft = fb.BeginTransaction();

FbCommand fc = new FbCommand("ADD_CLIENTE",fb,ft);
fc.CommandType = CommandType.StoredProcedure;

fc.Parameters.Add("@NAME",FbType.VarChar,255,"NAME");
fc.Parameters.Add("@EMAIL",FbType.VarChar,75,"EMAIL");
fc.Parameters.Add("@ACTIVATED",FbType.Char,1,"ACTIVATED");
fc.Parameters[0].Value = Server.HtmlEncode(txtName.Text);
fc.Parameters[1].Value = Server.HtmlEncode(txtName.Text);
fc.Parameters[2].Value = cboActivated.SelectedItem.Value;

fc.ExecuteReader(CommandBehavior.Default);

ft.Commit();
fb.Close();


and here is the error I get:

Code:
Exception Details: FirebirdSql.Data.INGDS.GDSException: Exception of type FirebirdSql.Data.INGDS.GDSException was thrown.


[GDSException: Exception of type FirebirdSql.Data.INGDS.GDSException was thrown.]
   FirebirdSql.Data.Firebird.FbStatement.Prepare() +392
   FirebirdSql.Data.Firebird.FbCommand.Prepare() +408

[FbException: Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, char 1
ADD_CLIENTE
]


I'm using Firebird.NEt Data Provider v1.0

If anyone can help me out....
Thanks

Reply With Quote
  #2  
Old June 12th, 2003, 01:05 PM
mariuz's Avatar
mariuz mariuz is offline
Bug Hunter
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Transylvania (Romania)
Posts: 274 mariuz User rank is Corporal (100 - 500 Reputation Level)mariuz User rank is Corporal (100 - 500 Reputation Level)mariuz User rank is Corporal (100 - 500 Reputation Level)mariuz User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 19 h 57 m 57 sec
Reputation Power: 9
this is an example done by carlos

I think is better to run "EXECUTE PROCEDURE(@NAME,@EMAIL,@ACTIVATED)" statement with the FbCommand
Here is how i would write it :
Quote:
FbConnection fb = new FbConnection(myConnectionString);
Fb.Open();
FbTransaction ft = fb.BeginTransaction();

FbCommand fc = new FbCommand("EXECUTE PROCEDURE ADD_CLIENTE(@NAME,@EMAIL,@ACTIVATED)",fb,ft);
fc.CommandType = CommandType.StoredProcedure;

fc.Parameters.Add("@NAME",FbType.VarChar,255,"NAME").Direction =
ParameterDirection.Input;
fc.Parameters.Add("@EMAIL",FbType.VarChar,75,"EMAIL").Direction =
ParameterDirection.Input;
fc.Parameters.Add("@ACTIVATED",FbType.Char,1,"ACTIVATED").Direction =
ParameterDirection.Input;
fc.Parameters[0].Value = Server.HtmlEncode(txtName.Text);
fc.Parameters[1].Value = Server.HtmlEncode(txtName.Text);
fc.Parameters[2].Value = cboActivated.SelectedItem.Value;

fc.ExecuteNonQuery();

ft.Commit();
fb.Close();


And carlos(.net provider creator) example :
I'm making test with C# here is my test case:

FbTransaction myTransaction;
FbConnection myConnection = new FbConnection(connectionString);

myConnection.Open();

myTransaction = myConnection.BeginTransaction();

FbCommand myCommand = new FbCommand("EXECUTE PROCEDURE
GETVARCHARFIELD(?)", myConnection, myTransaction);

myCommand.CommandType = CommandType.StoredProcedure;

myCommand.Parameters.Add("@INT_FIELD", FbType.Integer).Direction =
ParameterDirection.Input;
myCommand.Parameters[0].Value = 1;

myCommand.Parameters.Add("@VARCHAR_FIELD", FbType.VarChar).Direction =
ParameterDirection.Output;

myCommand.ExecuteNonQuery();

Console.WriteLine(myCommand.Parameters[1].Value);

myTransaction.Commit();

myConnection.Close();

Console.ReadLine();


And this is my test SP:

CREATE PROCEDURE GETVARCHARFIELD (
ID INTEGER)
RETURNS (
VARCHAR_FIELD VARCHAR(100))
AS
begin
for select varchar_field from test_table_01 where int_field = :id
into :varchar_field
do
suspend;
end



--
Best regards

Carlos Guzma'n A'lvarez
Vigo-Spain
__________________
My home page: http://www.firebirdsql.org and work place :http://www.reea.net

Last edited by mariuz : June 12th, 2003 at 01:28 PM.

Reply With Quote
  #3  
Old June 12th, 2003, 04:23 PM
fetcher fetcher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Portugal
Posts: 106 fetcher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 11 m 33 sec
Reputation Power: 6
Talking

Thanks a lot! It works now.

The more I learn about firebird the more I like it. And congratulations on the job with the FireBird .net Data Provider. It is simply great.

Reply With Quote
  #4  
Old June 12th, 2003, 04:59 PM
mariuz's Avatar
mariuz mariuz is offline
Bug Hunter
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Transylvania (Romania)
Posts: 274 mariuz User rank is Corporal (100 - 500 Reputation Level)mariuz User rank is Corporal (100 - 500 Reputation Level)mariuz User rank is Corporal (100 - 500 Reputation Level)mariuz User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 19 h 57 m 57 sec
Reputation Power: 9
Talking here is the .net provider list where you can subscribe

Quote:
Originally posted by fetcher
Thanks a lot! It works now.

The more I learn about firebird the more I like it. And congratulations on the job with the FireBird .net Data Provider. It is simply great.

Good
If you need more help then here is the .net provider list
where you can subscribe (Carlos Alvarez is on the list and he knows more advanced things about provider - he wrote it)

http://lists.sourceforge.net/lists/...rd-net-provider

Last edited by mariuz : June 12th, 2003 at 05:01 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > FireBird 1.5 RC3 and Stored Procedures w/ FireBird.Net Data provider


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway