Click here to Skip to main content
11,802,762 members (69,118 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WCF
I use FirebirdSql.Data.FirebirdClient unit to connect Firebird database.
Error allows in next unit when i trying get id of generator.

My unit where i get id of generator

public int GetId()
            FbConnection fbcon = new FbConnection(OpenConnection());
            FbCommand getId = new FbCommand();            
            getId.CommandText = "select GEN_ID(SOMEGENERATOR,1) from RDB$DATABASE";
            getId.Connection= fbcon;        

            FbDataReader fbrd=getId.ExecuteReader();
            return fbrd.GetInt32(0);
Error like this:
Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index
Posted 17-Sep-12 9:57am
Edited 17-Sep-12 9:58am
(no name)104.2K
Wes Aday at 17-Sep-12 15:59pm
"return fbrd.GetInt32(0);", there is nothing at index 0
konah at 17-Sep-12 16:05pm
Mistake allows at parameter fbcon.

In another unit same mistake. Unit:
public int CreateQueue(string queueName)
FbConnection fbcon = new FbConnection(OpenConnection());
int i=3;
crQueue.CommandType = CommandType.Text;
crQueue.CommandText = "insert into queue values (@id,@name,@current_status_id)";
crQueue.Parameters.Add("@id", FbDbType.Numeric).Value =5; crQueue.Parameters.Add("@name", FbDbType.VarChar).Value = queueName; crQueue.Parameters.Add("@current_status_id",FbDbType.Numeric).Value=i++; crQueue.Connection = fbcon;
return 1;
Wes Aday at 17-Sep-12 16:25pm
Well look at your OpenConnection function and see what is in there.
konah at 18-Sep-12 2:12am
In openconnection function i have code like this:

public string OpenConnection()
//string res;
//FbConnectionStringBuilder fb_con = new FbConnectionStringBuilder();
//fb_con.Charset = Charset;
//fb_con.Database = LogonDatabase;
//fb_con.UserID = User;
//fb_con.Password = Password;
//fb_con.ServerType = 0;

string strConnect = "User=" + User + ";Password=" + Password + ";Database=" + LogonDatabase + ";DataSource="+Server+"; Port=3050;" +
"Dialect=" + Dialect + "; Charset=" + Charset + ";Role=;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=50;"+
"Packet Size=8192;ServerType=0;";
//FbConnection fbcon = new FbConnection(strConnect);
//fbcon.ConnectionString = strConnect;
//if (fbcon.State == ConnectionState.Open)
//{res = true;
//{res = false;
// fbcon.Close();}
return strConnect;

The variables User,Password and others i take from global variables

public string strConnect;
public string User = ConfigurationManager.AppSettings["User"];
public string Password = ConfigurationManager.AppSettings["Password"];
public string LogonDatabase = ConfigurationManager.AppSettings["LogonDatabase"];
public string Server = ConfigurationManager.AppSettings["Server"];
public string Charset = ConfigurationManager.AppSettings["Charset"];
public string Dialect = ConfigurationManager.AppSettings["Dialect"];

of config file App.config

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 CPallini 270
4 Sergey Alexandrovich Kryukov 239
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,695
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100