开发者

"Attempted to read or write protected memory" when filling a DataTable

开发者 https://www.devze.com 2023-02-25 09:11 出处:网络
I am developing some reports using ReportViewer and at certain point I have to connect to an Oracle database to retrieve some data and store it in a DataTable.

I am developing some reports using ReportViewer and at certain point I have to connect to an Oracle database to retrieve some data and store it in a DataTable.

When the DataAdapter executes the Fill method I get this error:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Here's the code(unfortunatelly I can't put that sql code inside a procedure or something):

OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["Premio"].ConnectionString);
        OleDbCommand objCmd = new OleDbCommand();
        DataTable objDt = new DataTable();
int vTipoTerr = LoadTipoTerritorio(ReportParameter.ReportData.Parameters.Item("pTerritorio").Value.ToString());
            string vDataParametroDataFinal = ReportParameter.ReportData.Parameters.Item("pMesAnoCompetencia").Value.ToString();
            int vDataInicial = int.Parse(vDataParametroDataFinal.Substring(0, 4));
            vDataInicial = vDataInicial - 1;
            vDataInicial = int.Parse(vDataInicial.ToString() + vDataParametroDataFinal.Substring(4, 2)); 


objCmd.CommandText = "SELECT   T.Nome, " +
                                 "          T.Prontuario, " +
                                 "          C.Cobertura, " +
                                 "          Cn.Mesano_competencia, " +
                                 "        G.Grupo, " +
                          开发者_运维百科       "        T.Territorio, " +
                                 "        N.Negocio " +
                                 "     FROM Calculo C " +
                                 "    Inner Join Territorio T " +
                                 "       ON C.Id_Territorio = T.Id_Territorio " +
                                 "    Inner Join Grupo G " +
                                 "       ON C.Id_Grupo = G.Id_Grupo " +
                                 "    Inner Join Cenario Cn " +
                                 "       On Cn.Id_cenario = C.Id_cenario " +
                                 "    Inner Join Negocio N " +
                                 "       On Cn.Id_negocio = N.Id_negocio " +
                                 "    Where Cn.Mesano_competencia Between :p1 And :p2 --datas " +
                                 "      And G.Grupo = :p3 " +
                                 "      And Sub_terr(T.Territorio, Decode(:p4, 1, 'SETOR', 2, 'DISTRITO', 3, 'REGIONAL')) = :p5 " +
                                 "      And (Cn.Flag_cenario_disp = 1 Or Cn.Flag_cenario_disp_rec = 1) " +
                                 "      And N.Negocio = :p6 " +
                                 "      And Cn.Flag_recuperacao = 0 " +
                                 "      Order By Cn.Mesano_competencia; " +
                                 "union all " +
                                 "SELECT T.Nome, " +
                                 "        T.Prontuario, " +
                                 "        C.Cobertura, " +
                                 "        Cn.Mesano_competencia, " +
                                 "        G.Grupo, " +
                                 "        T.Territorio, " +
                                 "        N.Negocio " +
                                 "     FROM Calculo_Rec C " +
                                 "    Inner Join Territorio T " +
                                 "       ON C.Id_Territorio = T.Id_Territorio " +
                                 "    Inner Join Grupo G " +
                                 "       ON C.Id_Grupo = G.Id_Grupo " +
                                 "    Inner Join Cenario Cn " +
                                 "       On Cn.Id_cenario = C.Id_cenario " +
                                 "    Inner Join Negocio N " +
                                 "       On Cn.Id_negocio = N.Id_negocio " +
                                 "    Where Cn.Mesano_competencia Between :p1 And :p2  " +
                                 "      And G.Grupo = :p3 " +
                                 "      And Sub_terr(T.Territorio, Decode(:p4, 1, 'SETOR', 2, 'DISTRITO', 3, 'REGIONAL')) = :p5 " +
                                 "      And (Cn.Flag_cenario_disp = 1 Or Cn.Flag_cenario_disp_rec = 1) " +
                                 "      And N.Negocio = :p6 " +
                                 "      And Cn.Flag_recuperacao = 1 " +
                                 "      Order By Cn.Mesano_competencia ";
objCmd.Parameters.Add(new OleDbParameter("p1", OleDbType.Integer)).Value = vDataInicial;
            objCmd.Parameters.Add(new OleDbParameter("p2", OleDbType.Integer)).Value = int.Parse(vDataParametroDataFinal);
            objCmd.Parameters.Add(new OleDbParameter("p3", OleDbType.VarChar, 30)).Value = ReportParameter.ReportData.Parameters.Item("pGrupo").Value.ToString();
            objCmd.Parameters.Add(new OleDbParameter("p4", OleDbType.Integer)).Value = vTipoTerr;
            objCmd.Parameters.Add(new OleDbParameter("p5", OleDbType.VarChar, 30)).Value = ReportParameter.ReportData.Parameters.Item("pTerritorio").Value.ToString();
            objCmd.Parameters.Add(new OleDbParameter("p6", OleDbType.VarChar, 30)).Value = ReportParameter.ReportData.Parameters.Item("pNegocio").Value.ToString();

            OleDbDataAdapter objAdapter = new OleDbDataAdapter(objCmd);

            objConn.Open();

            objAdapter.Fill(objDt);

            objConn.Close();

Thank you very much (:


Try using OracleCommand and OracleConnection objects instead:

OracleConnection objConn = new OracleConnection (ConfigurationManager.ConnectionStrings["Premio"].ConnectionString);
    OracleCommand objCmd = new OracleCommand ();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号