This code gives exception: System.ArgumentOutOfRangeException
ArrayList conarr = new ArrayList();
conarr.Add("User ID=sysdba;Password=wrongpass1;" +
"Database=C:\\prod\\file.fdb;DataSource=192.168.0.5;Charset=NONE; Connection Timeout=30;Pooling=false;");
conarr.Add("User ID=sysdba;Password=wrongpass2;" +
"Database=C:\\prod\\file.fdb;DataSource=192.168.0.5;Charset=NONE; Connection Timeout=30;Pooling=false;");
conarr.Add("User ID=sysdba;Password=GOODPASS;" +
"Database=C:\\prod\\file.fdb;DataSource=192.168.0.5;Charset=NONE; Connection Timeout=30;Pooling=false;");
for (int t = 0; t < conarr.Count; t++)
{
Thread tr = new Thread(delegate()
{
trycon(conarr[t].ToString()); //<---------
});
tr.Start();
}
But if I change this thread creation to:
for (int t = 0; t < conarr.Count; t++)
{
string cs = conarr[t].ToString(); //<------
Thread tr = new Thread(delegate ()
{
trycon(cs); //<-------
});
tr.Start();
}
...then it works fine. Why?
This code is for searching which connection to database is good and which one is wrong, in separate parallel threads.