Error while compiling a web application

Asked

Viewed 64 times

1

How to solve this problem?

I have an application in dot.net and when compiling this message appears. I didn’t want to let this directory be default.

How can I fix it? Would anyone have any idea what can be done?

Could not find 'C: Program Files (x86) Common Files Microsoft Shared Devserver 10.0 Documents'.

 protected void importar_Click(object sender, EventArgs e)
        {
            // Antes de importar o arquivo, verifica se contém o arquivo
            if (selecionarArquivo.HasFile)
            {
                // Obter o nome da planilha do excel para carregar.
                if (Path.GetExtension(selecionarArquivo.FileName) != ".xlsx" && Path.GetExtension(selecionarArquivo.FileName) != ".xls")
                    ClientScript.RegisterStartupScript(typeof(string), "Erro", "<script>alert('Somente arquivos em excel')</script>");

                else
                {
                    if (selecionarArquivo.FileContent != null)
                    {
                        string Excel = AppDomain.CurrentDomain.BaseDirectory + selecionarArquivo.FileName;
                        selecionarArquivo.SaveAs(Excel);
                    }

                    // Gerando uma string de conexão para o arquivo excel.
                    string strExcelConn = "@DATA SOURCE=DAPP;PASSWORD=APL_SD7#PP4;USER ID=APL_SDP";

                    DataTable dtExcel = RetrieveData(strExcelConn);

                    // Obtendo as contagens das linhas, antes de importar.
                    int iStartCount = GetRowCounts();

                    // Importar os dados.
                    SqlBulkCopyImport(dtExcel);

                    int iEndCount = GetRowCounts();


                }
            }
        }


        // Obter as contagens de linhas na tabela do SQL Server
        protected int GetRowCounts()
        {
            int iRowCount = 0;


            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["@DATA SOURCE=DAPP;PASSWORD=APL_SD7#PP4;USER ID=APL_SDP"].ToString()))
            {
                SqlCommand cmd = new SqlCommand("select count(*) from SDPJ_IMPORT_PROCESSO", conn);
                conn.Open();

                // Executa o SqlCommand e obtendo as contagens da linhas.
                iRowCount = (int)cmd.ExecuteScalar();
            }

            return iRowCount;
        }

        // Recupar dados da planilha do Excel.
        protected DataTable RetrieveData(string strConn)
        {


            DataTable dtExcel = new DataTable();

            using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Documentos;Persist Security Info=False;"))
            {

                // Inicializando um objeto OleDbDataAdapter.
                OleDbDataAdapter da = new OleDbDataAdapter("select * from sdpj_import_processo", conn);


                // Preenchendo o DataTable com dados da planilha do Excel
                da.Fill(dtExcel);
            }

            return dtExcel;
        }


        private void SqlBulkCopyImport(DataTable dtExcel)
        {

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[@"DATA SOURCE=DAPP;PASSWORD=APL_SD7#PP4;USER ID=APL_SDP;"].ToString()))

            //@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="" + caminho + "";Extended Properties='Excel 12.0;HDR=No;IMEX=1';"
            {
                // Abrir conexão.
                conn.Open();

                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn))
                {
                    // Especificando o nome do destino da tabela.
                    bulkCopy.DestinationTableName = "sdpj_import_processo";

                    foreach (DataColumn dc in dtExcel.Columns)
                    {
                        // Como o numeros das colunas do excel 
                        // não é igual ao numeros de colunas da tabela, precisamos mapear as colunas.

                        bulkCopy.ColumnMappings.Add(dc.ColumnName, dc.ColumnName);
                    }

                    // Escreva o destino do arquivo.
                    //Define o nome da tabela

                    //[OPTIONAL]: Mapeie as colunas do Excel com a da tabela do banco de dados 
                    bulkCopy.ColumnMappings.Add("Data de Requisição Pgto", "DAT_REQ_PGTO");
                    bulkCopy.ColumnMappings.Add("NUMERO PROCESSO ANTERIOR", "NUM_PROC_ANTERIOR");
                    bulkCopy.ColumnMappings.Add("NUMERO JUDICIAL", "NUM_PROC_JUDICIAL");
                    bulkCopy.ColumnMappings.Add("COMARCA", "DSC_COMARCA");
                    bulkCopy.ColumnMappings.Add("VARA", "NUM_VARA");
                    bulkCopy.ColumnMappings.Add("VARANOME", "NME_VARA");
                    bulkCopy.ColumnMappings.Add("NOME", "NME_INTERESSADO");
                    bulkCopy.ColumnMappings.Add("CPF", "CPF_CNPJ_INTERESSADO");
                    bulkCopy.ColumnMappings.Add("DEENDERECO", "DSC_ENDERECO");
                    bulkCopy.ColumnMappings.Add("NUENDERECO", "NUM_ENDERECO");
                    bulkCopy.ColumnMappings.Add("NMMUNICIPIO", "NME_MUNICIPIO");
                    bulkCopy.ColumnMappings.Add("DECOMPLEMENTO", "DSC_DECOMPLEMENTO");
                    bulkCopy.ColumnMappings.Add("DEBAIRRO", "NME_BAIRRO");
                    bulkCopy.ColumnMappings.Add("NUCEP", "NUM_CEP");
                    bulkCopy.ColumnMappings.Add("NMMUNICIPIO", "NME_MUNICIPIO");
                    bulkCopy.ColumnMappings.Add("BRUTO", "VLR_BRUTO");
                    bulkCopy.ColumnMappings.Add("IRPF", "VLR_IR");
                    bulkCopy.ColumnMappings.Add("LIQUIDO", "VLR_LIQUIDO");
                    bulkCopy.ColumnMappings.Add("Nº SEP", "COD_SEP");
                    bulkCopy.ColumnMappings.Add("DATA SEP", "DAT_SEP");
                    bulkCopy.ColumnMappings.Add("DATA DE RECEBIMENTO NA ORIGEM", "DAT_RECEB_ORIGEM");

                    bulkCopy.WriteToServer(dtExcel);

                }
            }
        }
    }
}
  • 1

    Post the part of the code that is giving the error

  • protected Datatable Retrievedata(string strConn) {Datatable dtExcel = new Datatable(); using (Oledbconnection Conn = new Oledbconnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Documents;Persist Security Info=False;")) {// Initializing an Oledbdataadapter object. Oledbdataadapter da = new Oledbdataadapter("select * from sdpj_import_process", Conn);// Filling the Datatable with Excel sheet data da.Fill(dtExcel); }Return dtExcel; }

  • is giving error in this code above, in this line of. Fill(dtExcel);

  • I would like to see a way to prevent this directory from being standard to be able to compile.

  • how is your strConn?

  • Leandro Angelo posted all my code regarding the functionality of the import situation to better understand. What do you think can be?

  • Your Data Source=Documents; not found.... change the connection to an Oledbconnection validated path("Provider=Microsoft.ACE.OLEDB.12. 0;Data Source=Documents;Persist Security Info=False;"))

  • For security reasons, I recommend editing your post and hiding your password passed as a parameter in your connection string.

  • The password and user I put is fake hahaha, leave more standardized :), after the change was like this:

  • using (Oledbconnection Conn = new Oledbconnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C: Dative 96-1 Documents;Persist Security Info=False;")) { // Initializing an Oledbdataadapter object. Oledbdataadapter da = new Oledbdataadapter("select * from sdpj_import_process", Conn);// Filling the Datatable with Excel sheet data da.Fill(dtExcel); } Return dtExcel;

  • The error message is now: System.Data.Oledb.Oledbexception was unhandled by user code Hresult=-2147467259 Message='C: Documents 96-1 Dative' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.