Error when connecting to oracle database using web programming on . net

Asked

Viewed 441 times

1

When making attempts to connect to the bank I obtained the error according to the attached image. My application is web in . net, visual studio 2010, oracle sql database developed 3.1.07.

My code showing the error:

protected int GetRowCounts()
    {
        int iRowCount = 0;


        using (OracleConnection conn = new OracleConnection("DATA SOURCE=DAPP;PASSWORD=APL_SD7#PP4;USER ID=APL_SDP"))
        {
            OracleCommand cmd = new OracleCommand("select count(*) from SDPJ_IMPORT_PROCESSO", conn);
            conn.Open();

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

        return iRowCount;
    }

Erro

  • 1

    Just correcting :D you wrote dot net., but it doesn’t make sense. It’s dotnet or .Net, after all dot is dot in English. If you write dot net. would be the same as dotdotnet or ..net.

2 answers

2

Check in the directory

C: app product 11.1.0 client_1 network admin

and look for the file tnsnames., inside that file will be the database access settings. It loads these settings to access the database, if any data is wrong, it fails to load this information and triggers the error you reported.

0

That method GetRowCounts() is with protected access. Which means it will only run within the class itself. If you are trying to run it in another class, then you need to change the method access to public or create an access method public in the same class of GetRowCounts(), call you inside this new method and execute the new method in the place where you want.

  • I made the change as you suggested, but came back with the following error: ORA-12154: TNS:could not resolve the specified connect Identifier. The error happens in this code: public int Getrowcounts() {int iRowCount = 0; using (Oracleconnection Conn = new Oracleconnection("DATA SOURCE=DAPP;PASSWORD=APL_SD7#PP4;USER ID=APL_SDP") { Oraclecommand cmd = new Oraclecommand("select Count(*) from SDPJ_IMPORT_PROCESSO", Conn); Open(); iRowCount = (int)cmd.Executescalar(); }Return iRowCount; }

  • It does what Wagner Barbosa Do Nascimento suggested. Apparently, the connection error persists because of some invalid data. Check if the host, bank name, user and password are correct. But keep that procedure I told you about, otherwise the method won’t run if it’s protected and you try to call it out of your class.

  • Opa personal, made by the tips, I solved my problem, thank you very much, I posted another doubt, if someone can help me

Browser other questions tagged

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