Click here to Skip to main content
Rate this: bad
good
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.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 17-Sep-12 10:57am
konah579
Edited 17-Sep-12 10:58am
(no name)94.3K
v2
Comments
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;
fbcon.Open();
crQueue.ExecuteNonQuery();
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;
//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)

  Print Answers RSS
0 OriginalGriff 270
1 Sergey Alexandrovich Kryukov 185
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
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