Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

C#
public int GetId()
        {
            FbConnection fbcon = new FbConnection(OpenConnection());
            FbCommand getId = new FbCommand();            
            
            getId.CommandType=CommandType.Text;
            getId.CommandText = "select GEN_ID(SOMEGENERATOR,1) from RDB$DATABASE";
            getId.Connection= fbcon;        
    
            //fbcon.ServerVersion=;
            //fbcon.ServerVersionNumber=;
            
            fbcon.Open();


            FbDataReader fbrd=getId.ExecuteReader();
            fbrd.Read();
            
            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
Updated 17-Sep-12 9:58am
v2
Comments
[no name] 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;
fbcon.Open();
crQueue.ExecuteNonQuery();
return 1;
}
[no name] 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;
//fbcon.Open();
//if (fbcon.State == ConnectionState.Open)
//{res = true;
//fbcon.Close();}
//else
//{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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900