Click here to Skip to main content
11,925,896 members (61,314 online)
Rate this:
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 10:57am
Edited 17-Sep-12 10:58am
Wes Aday104.2K
Wes Aday 17-Sep-12 15:59pm
"return fbrd.GetInt32(0);", there is nothing at index 0
konah 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 17-Sep-12 16:25pm
Well look at your OpenConnection function and see what is in there.
konah 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.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