gpt4 book ai didi

c# - 这是错误 ORA-12154 : TNS:could not resolve the connect identifier specified?

转载 作者:可可西里 更新时间:2023-11-01 08:15:58 25 4
gpt4 key购买 nike

我有这段代码:

OracleConnection con = new OracleConnection("data source=localhost;user id=fastecit;password=fastecit"); 
con.Open(); string sql="Select userId from tblusers";
OracleCommand cmd = new OracleCommand(sql, con);
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{ messageBox.Show(dr[0].Tostring()); }

两个项目中的代码相同,

在项目 1 中“WinForm”工作正常

在 project2 "Excel 2007 addins"出现以下错误:

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

我正在使用 C#.net 2010、office 2007、windows8、oracle 10g。

准备手动连接数据库时,如图

Visual Studio,打开“查看”菜单 + 服务器资源管理器。

右击数据连接+添加连接+选择Oracle数据库服务器名称:本地主机或我的机器名称,设置用户名和密码并单击测试连接,测试没有成功。 enter image description here

最佳答案

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

如果 TNS 没有定义你也可以试试这个:

如果你使用的是C#.net 2010或者其他版本的VS和oracle 10g express edition或者更低的版本,并且你的连接字符串是这样的:

static string constr = @"Data Source=(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=yourhostname )(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));
User Id=system ;Password=yourpasswrd";

之后您会收到错误消息 ORA-12154:TNS:无法解析指定的连接标识符 然后首先您必须重新启动系统并运行您的项目。

如果您的 Windows 是 64 位,那么您需要安装 oracle 11g 32 位,如果您安装 11g 64 位,那么您需要安装 Oracle 11g Oracle 数据访问组件 (ODAC) 和 Oracle Developer Tools for Visual Studio version 11.2。来自 OTN 的 0.1.2 或更高版本并在 Oracle Universal Installer 中检查它请确保检查以下内容:

Oracle Data Provider for .NET 2.0

Oracle Providers for ASP.NET

Oracle Developer Tools for Visual Studio

Oracle Instant Client

然后重新启动您的 Visual Studio,然后运行您的项目....注意:- 必须重新启动系统才能解决此类错误......

关于c# - 这是错误 ORA-12154 : TNS:could not resolve the connect identifier specified?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20361325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com