oracle连接字符串与C#使用oledb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12756264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 00:20:27  来源:igfitidea点击:

oracle connection String with C# using oledb

c#oracledatabase-connectionoledb

提问by Angelo Gabriel Escudero Vía

Im developing an application in C# that connects to Oracle 10g.

我在 C# 中开发了一个连接到 Oracle 10g 的应用程序。

When I use ODP. Net and this

当我使用 ODP 时。网和这个

Connection String "Data Source=Angelo-HP/XE;User ID=MAPFRE;Password=123456"I can connect and perform any action with the database,

连接字符串"Data Source=Angelo-HP/XE;User ID=MAPFRE;Password=123456"我可以连接数据库并执行任何操作,

but when I use OleDbConnection (System.Data.OleDb) with this

但是当我使用 OleDbConnection (System.Data.OleDb) 时

connection String: "Provider=OraOLEDB.Oracle;OLEDB.NET=true;PLSQLRSet=true;User ID=mapfre;password=123456;Data Source=XE"I got this error:

连接字符串:“Provider=OraOLEDB.Oracle;OLEDB.NET=true;PLSQLRSet=true;User ID=mapfre;password=123456;Data Source=XE”我收到这个错误:

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

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

When I try use Open() method from OleDbConnection.

当我尝试使用 OleDbConnection 中的 Open() 方法时。

I think is not oracle configuration because I can connect from ODP and sqldeveloper client.

我认为不是 oracle 配置,因为我可以从 ODP 和 sqldeveloper 客户端连接。

Any idea?

任何的想法?

Thanks,

谢谢,

回答by Jace

Try the connection strings at the link below:

尝试以下链接中的连接字符串:

Oracle Connection String Samples

Oracle 连接字符串示例

回答by Kumar

This issue may occur if you have multiple versions of oracle on your computer.

如果您的计算机上有多个版本的 oracle,则可能会出现此问题。

try these steps

试试这些步骤

  1. go to network folder of oracle and open tnsnames.ora
  2. search for the your DB name (XE in this case)
  3. this will have your data source information (EX : (DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(Host = xx.xx.xx.xx)(Port = xxxx)))(CONNECT_DATA =(SERVICE_NAME = XP))))
  4. use this in Data source field of your connection string . (EX: Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(Host = xx.xx.xx.xx)(Port = xxxx)))(CONNECT_DATA =(SERVICE_NAME = XP)));")
  1. 转到oracle的网络文件夹并打开tnsnames.ora
  2. 搜索您的数据库名称(在本例中为 XE)
  3. 这将包含您的数据源信息(EX : (DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(Host = xx.xx.xx.xx)(Port = xxxx)))(CONNECT_DATA =(SERVICE_NAME = XP) )))
  4. 在连接字符串的数据源字段中使用它。(例如:数据源=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(Host = xx.xx.xx.xx)(Port = xxxx)))(CONNECT_DATA =(SERVICE_NAME = XP)));" )

also, make sure your solution was built in anyCPU mode and make sure in App Pool enable 32 bit is true

另外,请确保您的解决方案是在 anyCPU 模式下构建的,并确保在 App Pool 中启用 32 位为真