Hi fellows, I need your help on this I have a ..... "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}..... Error
public ArrayList lineAccess=new ArrayList();
public void configTxt(string ficheiro)
{
StreamReader conjLines;
string lines;
try
{
conjLines = new StreamReader(ficheiro);
lines = conjLines.ReadLine();
while (lines != null)
{
lineAccess.Add(lines);
lines = conjLines.ReadLine();
}
conjLines.Close();
}
catch (Exception erro)
{
throw erro;
}
}
-----------------------------------------------------------------------------------------------
this is my connection method, and I get the server name at some txt file
public string conectaSql(int i)
{
//string connectionString = Properties.Settings.Default.ConnectionString;
string dv = "";
try
{
string mysql = "select configura from conStringTbl where id= '" + i + "'";
using (SqlConnection myconn = new SqlConnection("Persist Security Info=False;Server=" + lineAccess[0] +"; DataBase=dbconString; user=ka; password =newbegining"))
{
myconn.Open();
using (SqlCommand comand = new SqlCommand(mysql, myconn))
{
SqlDataReader dtreader = comand.ExecuteReader();
if (dtreader.Read())
{
dv = dtreader[0].ToString();
}
return dv;
}
}
}
catch (Exception erro)
{
throw erro;
}
}
______________________________________________on form login load I get the parameter
private void frmLogin_Load(object sender, EventArgs e)
{
CG.configTxt(@"c:\program Files\a.txt");
}
Thanks!!!!!

VulpesRank #55 · 29.2K reputationPosted Mar 4, 2014, 1:54 PM EST
So I'm totally mystified as to why it's still not working :-/
You might try inserting the MessageBox line in your own code to see what you get.
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Mar 1, 2014, 4:51 PM EST
Sousa Pambo92 reputationPosted Mar 2, 2014, 9:57 AM EST
Error is ..... {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
VulpesRank #55 · 29.2K reputationPosted Mar 2, 2014, 10:45 AM EST
If an index of 0 can't be found, then that would suggest that either there are no lines in the file or the file can't be found at all.
Sousa Pambo92 reputationPosted Mar 3, 2014, 3:41 AM EST
- I made some tests to see if it reads the file or not and I found it does (I changed the "a.txt" to "b.txt" the msg was "b" doesn't exist, this bug doesn't show for "a" file name).
- In the file ("a.txt") I only have "." because for while I testing my application with the local server, it means I have only one line to be read in the file.
So I don't understand the error.
Please help me on this!!!!!!!!!
VulpesRank #55 · 29.2K reputationPosted Mar 3, 2014, 4:23 AM EST
I notice that in frmLogin_Load you call the configTxt method like this:
CG.configTxt(@"c:\program Files\a.txt");
which suggests that it's in a different class to the form itself.
If so, is the declaration of the lineAccess ArrayList and the conectaSql method in the same class as configTxt or are they in the form itself?
What I'm wondering here is whether you might have inadvertently declared two ArrayLists one in the form and one in the class and that one of these is getting populated but the other one is still empty.
Sousa Pambo92 reputationPosted Mar 3, 2014, 9:47 AM EST
I have one declaration .... here is the code
---------------------------------------------------------------------------------------
Please check where I'm doing wrong!!!!!!
VulpesRank #55 · 29.2K reputationPosted Mar 3, 2014, 11:39 AM EST
Sousa Pambo92 reputationPosted Mar 4, 2014, 5:47 AM EST
Is there some more ideia, i'm empty now....
Sousa Pambo92 reputationPosted Mar 9, 2014, 11:28 AM EDT