0

i've this code in project "Excel 2007 Addins"

 private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        string constring = "data source=localhost;user id=fi_archivedb;Password=fi_archivedb";
        OracleConnection con = new OracleConnection(constring);
        string sql = "select *from TBLFOLDERS"; 
        con.Open();
        OracleCommand cmd = new OracleCommand(sql, con);

        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
            MessageBox.Show(dr[0].ToString());
    }

Error=: ORA-12154: TNS:could not resolve the connect identifier specified

Also i've Same code in project windowsApplaction :

   private void Form1_Load(object sender, EventArgs e)
    {
        string constring = "data source=localhost;user id=fi_archivedb;Password=fi_archivedb";
        OracleConnection con = new OracleConnection(constring);
        string sql= "select *from TBLFOLDERS"; 
        con.Open();
        OracleCommand cmd = new OracleCommand(sql, con);

        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
            MessageBox.Show(dr[0].ToString());
    }

In this project "WindowsApplaction" the code correctly without any error.

Where's the problem?

Why does not the code in the project "Excel 2007 Addins"?

  • You already asked this http://stackoverflow.com/questions/20361325/this-is-error-ora-12154-tnscould-not-resolve-the-connect-identifier-specified was the answer provided not sufficient? – Zach Spencer Dec 03 '13 at 23:32
  • yes ,the answer provided not sufficient – محمد النعيمي Dec 03 '13 at 23:35
  • This problem two days ago and I'm trying to solve, but to no avail, I hope that you will help me – محمد النعيمي Dec 03 '13 at 23:37
  • `localhost` maybe good for sql server. YOu need to setup tns_names file for oracle. Then use `tnsping` command in cmd to test your connectivity – T.S. Dec 04 '13 at 00:32
  • Yes, I want only one interpretation of the problem Why connection works correctly in prpject"WindowsApplaction" and does not work in the project "Excel 2007 Addins", although I use the same code and the same machine and the same version of Oracle and the same version of the C-Sharp – محمد النعيمي Dec 04 '13 at 00:58

1 Answers1

0

The TNS-xxxxx error points out that it is only an Oracle error.

Your connection string is not correctly set up. Oracle has it's own layer on top of I think any network protocol ever invented. It is named "TNS" for "Transparant Network Substrate". Using TNS (also known as "Oracle SQL*Net", also known as "Oracle Net"), you could in the dark ages transparently route packets from SNA to DECNet to IPX to IP based networks and back, without knowing anything about them. Currently, Oracle is switched to IP based only, but most users still use the old TNS layer.

To configure it, see for instance Oracle Net manual

Also, there are some recommendations to allow correct use of Unicode and easy use of a shared location using network files, please see 3.7.5.1.2 of configuration manual of Invantive product

In your case, since it sometimes seems to work, please check that you are comparing two identical installations, so use Excel 32-bit and Windows 32-bit. Or both 64-bit. Oracle has different DLL-s for the number of bits needed. And also different configuration files. As described in 2 you can share configuration files across multiple installation of Oracle SQL*Net using TNS_ADMIN in your registry.

Also note that especially with add-ins using VSTO it can be more complex to get an add-in that installs both into 32 and 64 bit Office environments to load the correct DLL always without hardcoding the versions and shipping the correct Oracle DLL-s with it. Also remember to use ODP, not the Microsoft variant. We've had initially major problems when we started in 2009 getting VSTO add-ins (Invantive Control for 32- and 64-bit Excel, some sheets required 64-bit to handle the full volume of data, please note limitations of .NET array in 4.0, consider 4.5) to run with any Oracle version installed (for instance 32-bit 10g or 11g might be encountered already installed) in combination with any Office version (why o why do people still run 32 bit....). The solution for that I can't share with you. Ultimately we have switched for smaller data volumes (< 4 GB in one request) to our own webservice which disentangles the client side from the server and which ensures that the user doesn't need to install 500 MB of Oracle client software. This might be a viable approach for you too.

Please note that there are others options too using Oracle SQL*Net, such as other directories with the available services as well as putting the following connect string and routing information in the .NET connection string.

Please note that you are missing a space between '' and 'from TBLFOLDERS' and that unnecessarily using a '' when you could suffice with just few fields can introduce performance issues (for instance due to an index not being selected even when it contained all necessary fields) and network bandwidth issues (dragging around a few KB extra on every roundtrip quickly increases the needed bandwidth).

A simple example of a tnsnames configuration file defining the service "XYZ.ACME.COM" or "XYZ":

# Include other file, new releases can nest them.
ifile=tnsnames-invantive.ora
# Direct in tnsnames.ora:
XYZ.ACME.COM=
( description =
  ( address_list =
    ( address = (protocol = tcp)(host = 192.1.1.1)(port = 1521)
    )
  )
  ( connect_data =
    (sid=XYZ)
    (global_name = XYZ.ACME.COM)
  )
)

Accompanying sqlnet.ora:

NAMES.DIRECTORY_PATH= (TNSNAMES)
NAMES.DEFAULT_DOMAIN=ACME.COM
DEFAULT_SDU_SIZE=65536
RECV_BUF_SIZE=1048576
SEND_BUF_SIZE=1048576

Did this fix your problem?

Guido Leenders
  • 4,232
  • 1
  • 23
  • 43
  • three cases : 1- when set Platform target =x86 this addin is load in office applaction ,but no conncted database . 2- when set Platform target =x64 this addin is not load in office applaction – محمد النعيمي Dec 04 '13 at 13:37
  • Hi, I am missing the third one; what version of Excel are you running? 32-bit or 64-bit? Please note that it is not a good idea to change the x32/x64 setting of an Office project; you should reflect your Office installation or allow the CLR to choose the x32/x64 and load the correct Oracle assembly in your own code. When running 32-bit, please ensure that you have 32-bit Oracle configured as described above. As a shortcut: use registry HKLM\SOFTWARE\Oracle\Key*\TNS_ADMIN to point to the tnsnames.ora. Did you follow other instructions? – Guido Leenders Dec 04 '13 at 14:01
  • How can I find version Excel ? – محمد النعيمي Dec 04 '13 at 14:22
  • One of the ways to determine the version of Excel in use is: Start Excel, File ribbon, click on Help. On the right side it says: "Product activated", ..., "About Microsoft Excel", Version: 14.0.7106.5003 (64-bit). So I am running 64-bit Excel of Office 2010 (v14). – Guido Leenders Dec 04 '13 at 14:55
  • Version: 14.0.4734.1000 (32 bit) – محمد النعيمي Dec 04 '13 at 15:21
  • Ok, platform target = x86 is for your current setup ok. If you need to deploy on 64-bit Office, you will have some additional challenges, but that is for later. For now, ensure that you are testing with 32-bit Oracle. For instance, start command prompt, go to 32-bit installation folder of Oracle (on my testing environment C:\oracle\x32\product\11.2.0\client_1\BIN, but I always put the number of bits in the path somewhere, I don't recall the normal location), and in that bin folder run 'tnsping SERVICENAME'. It will probably not work. It shows parameter files used. Follow instructions above. – Guido Leenders Dec 05 '13 at 08:31
  • Has this problem been fixed? – Guido Leenders Dec 22 '13 at 14:47
  • hi @محمد النعيمي was this answer helpful to solve your problem? If not please add what was not successful to your question. When the answer helped you, can you accept it by clicking the hollow green check mark next to it? – Guido Leenders Jan 31 '14 at 07:38
  • i'm sorry , Exactly this is the perfect solution to my problem – محمد النعيمي Feb 01 '14 at 07:17