VS2010 + Oracle驱动程序:ORA-12154:TSN:无法解析指定的连接标识符 [英] VS2010 + Oracle driver: ORA-12154: TSN:could not resolve the connect identifier specified

查看:1317
本文介绍了VS2010 + Oracle驱动程序:ORA-12154:TSN:无法解析指定的连接标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的:

  • 在Visual Studio 2010中
  • 的.NET Framework数据提供程序的Oracle
  • Oracle开发工具Visual Studio的(从Oracle的网站)

我尝试安装Oracle开发工具Visual Studio的创造的tnsnames.ora和sqlnet.ora中的文件在我的C:\程序\ [我的用户名] \产品\ 11.2.0 \ Client_1的\网络\管理目录。

I tried installing 'Oracle Developer Tools for Visual Studio' and created tnsnames.ora and sqlnet.ora files in my C:\app\ [my username]\product\11.2.0\client_1\Network\Admin directory.

他们是这样的:

# tnsnames.ora

ORATEST =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dbs-oratest)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = [ORATEST])
    )
  )

# sqlnet.ora

SQLNET.AUTHENTICATION_SERVICES= (ALL)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

当我尝试使用.NET Framework数据提供程序的Oracle驱动程序来设置新的连接(或任何其他驱动器的这个问题:OLE,ODBC等),它提供了错误:

When I try using the .Net Framework Data Provider for Oracle driver to set up a new connection (or any other driver for that matter: OLE, ODBC, etc) it gives the error:

ORA-12154:TSN:无法解析指定的连接标识符

一台机器的在使用OLE驱动程序,而不的安装Oracle客户端没有工作,但:

Using the OLE driver on a machine without the Oracle client installed DOES work though:

OleDbConnection conn = new OleDbConnection(
    "Provider=MSDAORA;Data Source=ORATEST;" + 
    "Persist Security Info=True;Password=readonly;User ID=readonlyuser");

我是什么做错了吗?有没有简单的联机说明有关如何安装一个基本的Oracle驱动程序?

What am I doing wrong? Are there any simple instructions online about how to install a basic Oracle driver?

感谢你在前进!

推荐答案

我发现使用Oracle数据访问客户端库,并在连接字符串在整个TNS名称条目中的最佳解决方案。这允许项目容易地发布到web服务器,ClickOnce的等

The best solution I found was to use the Oracle Data Access Client library, and include the entire TNS names entry in the connection string. This allows the project to be easily published to a web server, ClickOnce, etc.

下面是需要设置Oracle驱动程序在你的项目中工作的步骤:

Here are the steps necessary to set up the Oracle driver working in your project:

1)获取从DLL文件'的Oracle数据提供.NET包

下载安装程序文件: http://www.oracle .COM / technetwork /主题/ DOTNET /指数085163.html

我继续安装了完整的200 MB ODAC与Oracle开发工具Visual Studio中,但你只有真正需要四个DLL从这个下载。 (您可以直接从安装程序包中提取,而不是去完成整个安装过程中它们,或者较小的下载一个包括所有的人。)

I went ahead and installed the full 200 MB ODAC with Oracle Developer Tools for Visual Studio, but you only really need four DLLs from this download. (You may be able to extract them directly from the installer package, instead of going through the entire install process, or perhaps one of the smaller download includes all of them.)

2)引用的DLL在您的项目

搜索Oracle数据访问客户端的安装目录,然后拖动下面的四个DLL到项目的根目录下:

Search the installation directory of the Oracle Data Access Client and drag the following four DLLs into the root of your project:

  • Oracle.DataAccess.dll
  • OCI.DLL
  • oraciicus11.dll
  • OraOps11w.dll

复制到输出目录属性中的所有文件,除了Oracle.DataAccess.dll为复制总是

Set the Copy to Output Directory property all of the files except Oracle.DataAccess.dll to Copy always.

项目 - > 添加引用... ,点击浏览标签,并选择Oracle.DataAccess.dll文件。

Under Project --> Add Reference..., click on the Browse tab and select the Oracle.DataAccess.dll file.

3)使用具有完整的连接字符串的驱动程序(可选)

这样才不会担心TNS名称的文件正在设立的应用程序部署到的机器,我把整个定义在文件中,由所示的 connectionstrings.com 。它使连接字符串有点笨重,但去掉了很多的TNS名称文件头疼,我之前经历的:

So as not to have to worry about TNS names files being set up on the machines the application was deployed to, I put the entire definition in the file as shown by connectionstrings.com. It makes the connection string a little bulky, but removed a lot of the TNS Names file headaches I was experiencing before:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=servername)(PORT=‌​1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)));User Id=username;Password=********;

下面是我用来测试驱动程序中的满级:

Here's the full class I used to test the driver:

using System;
using System.Data;
using Oracle.DataAccess.Client;

static class Program
{
    [STAThread]
    static void Main()
    {
        TestOracle();
    }

    private static void TestOracle()
    {
        string connString = 
            "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)" + 
            "(HOST=servername)(PORT=‌​1521)))" +
            "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=servicename)));"+ 
            "User Id=username;Password=********;";
        using (OracleConnection conn = new OracleConnection(connString))
        {
            string sqlSelect = "SELECT * FROM TEST_TABLE";
            using (OracleDataAdapter da = new OracleDataAdapter(sqlSelect, conn))
            {
                var table = new DataTable();
                da.Fill(table);

                if (table.Rows.Count > 1) 
                    Console.WriteLine("Successfully read oracle.");
            }
        }
    }
}

这篇关于VS2010 + Oracle驱动程序:ORA-12154:TSN:无法解析指定的连接标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆