jeudi 3 septembre 2015

connection string property has not been initialized

I don't know why this code gives me an error. I am trying to put the sql commands into a transaction. This code gives me this error. I can't fill int anything else at the source than this. This is the error I get

Additional information: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

using (SQLiteConnection cn = new SQLiteConnection(string.Format("Data Source={0};")))
                    {
                        cn.Open();
                        using (SQLiteTransaction tr = cn.BeginTransaction())
                        {

                            sqlTarget = sqlInsert1 + columnList + ") VALUES (";
                            object[] sourceVal = new object[nCol];
                            rdrSourceTable.GetValues(sourceVal);
                            string strMsg = string.Empty;
                            int iCol = 0;
                            foreach (object col in sourceVal)
                            {
                                string columnName = rdrSourceTable.GetName(iCol++);
                                sqlTarget += objDbTarget.ObjectForSql(col, ref strMsg, false, columnName) +
                                             comma;
                            }
                            if (strMsg.Length > 0)
                            {
                                msg = string.Format(
                                    "The input values are wrong, strMsg = {0}\r\nThe composed sql = {1}",
                                    strMsg, sqlTarget);
                                if (m_interactive)
                                {
                                    DialogResult res = MessageBox.Show(msg, GetType().ToString(),
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                                    if (res == DialogResult.Cancel)
                                    {
                                        throw new CopyDbContentsException(msg);
                                    }
                                }
                                if (errorCount++ < 5)
                                {
                                    RadFile.WriteLogMsg("FillTableWithInsertCommands. " + msg +
                                                        "\r\n\r\nContinue?");
                                }
                                //Skip the insert action because of the error and go to next row.
                                continue;
                            }
                            sqlTarget = sqlTarget.Substring(0, sqlTarget.Length - comma.Length) + ")";
                            objDbTarget.ExecuteActionQuery(sqlTarget);
                            iRow++;
                            int remainder = iRow%250;
                            if (remainder == 0)
                            {
                                WriteStatusLabel(string.Format(
                                    "Copy the rows of table {0}. {1:N0} written.", Name,
                                    iRow));
                            }
                            remainder = iRow%nMsgMod;
                            if (remainder == 0)
                            {
                                msg = string.Format("{0:N0} rows of table {1} copied.",
                                    iRow, Name);
                                RadFile.WriteLogMsg(msg, withHeader: false);
                                if (nMsgMod < 100000 && iRow == 10*nMsgMod)
                                {
                                    nMsgMod *= 10;
                                }
                            }
                            tr.Commit();
                        }
                        cn.Close();
                    }
                }
                msg = string.Format("Table {0} is copied, {1:N0} rows. ", Name, iRow);
                        if (errorCount > 0)
                        {
                            msg += errorCount;
                            msg += (errorCount == 1) ? " row is" : " rows are";
                            msg += " skipped because of errors in the input";
                        }
                        RadFile.WriteLogMsg(msg, withHeader: false);
            }
        }

Aucun commentaire:

Enregistrer un commentaire