Beispiel #1
0
        //ATTENZIONE res se non è un ref non funziona
        public bool ExecQuery <T1>(string query, ref T1 res, QryOut @out = QryOut.dataTable, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, int timeOutQuery = 0, Mess logMess = null)
        {   //Attenzione: l'out come Datatable costa di più in termini di cpu, dataReader costa meno
            if (logMess == null)
            {
                logMess = new Mess(LogType.ERR, Log.main.errUserText);
            }
            logMess.testoDaLoggare = "";

            Thread thread; Exception thrEx = null; bool esito; string testoTmp;

            if (PreExec(true, query, ref strConn, nuovaConn, ref timeOutQuery, logMess) == false)
            {
                return(false);
            }

            if (res == null)
            {
                this.@out = @out;
            }
            else
            {
                if (res.GetType() == typeof(DataTable))
                {
                    this.@out = QryOut.dataTable;
                }
                else if (res.GetType() == typeof(OleDbDataReader))
                {
                    this.@out = QryOut.dataReader;
                }
                else
                {
                    logMess.testoDaLoggare = "ricevuto res con tipo disatteso, res.GetType.Name:<" + res.GetType().Name + ">";
                    Log.main.Add(logMess);
                    return(false);
                }
            }

            esito = false;
            //se si perde la connessione prima di eseguire cmd.ExecuteReader() (può succede per DB remoto quando si è già connessi, quindi con nuovaConn=False) passano 47 secondi prima che ritorna l'errore data provider interno 30,
            thread = Thr.AvviaNuovo(() => esito = ThrEQ_Exec(ref thrEx), ApartmentState.MTA); //Attenzione se STA, alla 'resOle.Close()' c'è l'eccezione: Impossibile utilizzare oggetti COM separati dai relativi RCW sottostanti.

            if (Thr.AttesaCompletamento(ref thread, timeOutQuery) == false)
            {
                logMess.testoDaLoggare = "query:<" + cmd.CommandText + "> andata in timeOut:<" + timeOutQuery + ">";
                Log.main.Add(logMess);
                return(false);
            }

            if (esito == false)
            {
                if (thrEx != null)
                {
                    if (FiltraEccezioniQuery(thrEx) == true)
                    {
                        logMess.testoDaVisual = "";
                        logMess.tipo          = LogType.Warn;
                    }
                    testoTmp = "ex.mess:<" + thrEx.Message + ">";
                }
                else
                {
                    testoTmp = "il thread ThrEQ_Exec è ritornato false ma senza eccezioni";
                }

                logMess.testoDaLoggare = "query:<" + cmd.CommandText + ">, " + testoTmp;
                Log.main.Add(logMess);
                return(false);
            }
            //Ho dovuto eseguire la resDt.Load(cmd.ExecuteReader()) nel delegato poichè se esegiuvo la resDt.Load(DataReader) qua da la seguente eccezione
            //Impossibile eseguire il cast di oggetti COM di tipo 'System.__ComObject' in tipi di interfaccia 'IRowset'. L'operazione non è stata completata perché la chiamata QueryInterface sul componente COM per l'interfaccia con IID '{ 0C733A7C - 2A1C - 11CE - ADE5 - 00AA0044773D}
            //non è riuscita a causa del seguente errore: Interfaccia non supportata. (Eccezione da HRESULT: 0x80004002 (E_NOINTERFACE)).

            if (res != null)
            {
                if (this.@out == QryOut.dataTable)
                {
                    res = (T1)(dynamic)ResDt;
                }
                else if (this.@out == QryOut.dataReader)
                {
                    res = (T1)(dynamic)ResOle;
                }
            }

            return(true);
        }
Beispiel #2
0
        public bool ExecQuery(string query, QryOut @out = QryOut.dataTable, NuovaConn nuovaConn = NuovaConn.seNecessario, StrConnection strConn = null, int timeOutQuery = 0, Mess logMess = null)
        {
            object res = null;

            return(ExecQuery(query, ref res, @out: @out, nuovaConn: nuovaConn, strConn: strConn, timeOutQuery: timeOutQuery, logMess: logMess));
        }