如何使用TNSName连接到Oracle数据库 [英] How to connect to Oracle DataBase using TNSName

查看:144
本文介绍了如何使用TNSName连接到Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试以这种方式连接到Oracle Server:

Hi,
I''m trying to connect to an Oracle Server in this way :

OracleConnection conn;
conn = new OracleConnection("User Id=usr;Password=pass;
Data Source=MyTnsName.world");
conn.Open();



我得到了这个错误:
ORA-12154: TNS:could not resolve the connect identifier specified

TNS正在工作,我与此Ton连接到Toad,而pingtns正在响应.

我有VS2010和c#WebForm.

谢谢.



And I got this error :
ORA-12154: TNS:could not resolve the connect identifier specified

The TNS is working, I connect in Toad with this TNS and pingtns is responding.

I have VS2010 and c# WebForm.

Thank you.

推荐答案

您尝试过吗? (来自http://ora-12154.ora-code.com/)

ORA-12154:TNS:无法解析指定的连接标识符
原因:使用连接标识符请求到数据库或其他服务的连接,并且使用配置的一种命名方法无法将指定的连接标识符解析为连接描述符.例如,如果使用的连接标识符的类型是网络服务名称,则在命名方法存储库中找不到网络服务名称,或者找不到或访问该存储库.
行动:-如果您使用本地命名(TNSNAMES.ORA文件):

•确保在Oracle Net概要文件(SQLNET.ORA)中将"TNSNAMES"列为NAMES.DIRECTORY_PATH参数的值之一.
•确认TNSNAMES.ORA文件存在并且在正确的目录中并且可以访问.

•检查TNSNAMES.ORA文件中是否存在用作连接标识符的网络服务名称.

•确保TNSNAMES.ORA文件中的任何地方都没有语法错误.查找不匹配的括号或流浪字符. TNSNAMES.ORA文件中的错误可能会使它无法使用.

•如果使用目录命名:

•验证"LDAP"是否已列为Oracle Net概要文件(SQLNET.ORA)中NAMES.DIRETORY_PATH参数的值之一.

•验证LDAP目录服务器是否已启动并且可访问.

•验证目录中是否配置了用作连接标识符的网络服务名称或数据库名称.

•通过指定完全限定的网络服务名称或完整的LDAP DN作为连接标识符来验证所使用的默认上下文是否正确

•如果使用轻松连接命名:

•验证"EZCONNECT"是否已列为Oracle Net概要文件(SQLNET.ORA)中NAMES.DIRETORY_PATH参数的值之一.

•确保指定的主机,端口和服务名称正确.

•尝试将连接标识符括在引号中.有关命名的更多信息,请参见《 Oracle Net Services管理员指南》或《 Oracle操作系统特定指南》.

在google的帮助下,我也找到了这些链接;

http://www.shabdar.org/connect-to-oracle- using-asp-net-and-csharp.html [ ^ ]

http://social.msdn.microsoft.com /forums/zh-CN/adodotnetdataproviders/thread/c3d287f1-e358-4e1c-a6c0-bb9c7cc0649b/ [
Have you tried this yet? (from http://ora-12154.ora-code.com/)

ORA-12154: TNS:could not resolve the connect identifier specified
Cause: A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.
Action: - If you are using local naming (TNSNAMES.ORA file):

•Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA)

•Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.

•Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.

•Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable.

•If you are using directory naming:

•Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).

•Verify that the LDAP directory server is up and that it is accessible.

•Verify that the net service name or database name used as the connect identifier is configured in the directory.

•Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier

•If you are using easy connect naming:

•Verify that "EZCONNECT" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).

•Make sure the host, port and service name specified are correct.

•Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.

With the help of google I found out these links as well;

http://www.shabdar.org/connect-to-oracle-using-asp-net-and-csharp.html[^]

http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/c3d287f1-e358-4e1c-a6c0-bb9c7cc0649b/[^]


我认为这有问题连接字符串

用这个

私有静态字符串CONNECTION_STRING =
用户ID = myUserID;密码= myPassword;数据源=(DESCRIPTION =" +
((地址=(协议= TCP)(主机= myserver.server.com)(端口= yourPort#))" +
(CONNECT_DATA =(SID = yourSID)​​));";

您还可以使用udl文件为您生成连接字符串.

如何制作UDL文件?

制作txt文件,另存为filename.udl,文件类型所有文件,单击保存

现在运行filename.udl

进行设置,测试连接,然后单击确定"

现在打开udl文件作为txt文件,连接字符串将出现在最后一行.


有关更多详细信息

http://www.codeproject.com/KB/database/C__Instant_Oracle.aspx
Hi, i think something wrong with connection string

use this

private static string CONNECTION_STRING =
"User Id=myUserID;Password=myPassword;Data Source=(DESCRIPTION=" +
"(ADDRESS=(PROTOCOL=TCP)(HOST=myserver.server.com)(PORT=yourPort#))" +
"(CONNECT_DATA=(SID=yourSID)));";

u can also use udl file to generate connection string for u.

How to make UDL file?

make txt file, save as filename.udl, file type All files, click save

now run filename.udl

do the settings, test connection, then click ok

now open udl file as txt file, connection string wil be there in last line.


For more details

http://www.codeproject.com/KB/database/C__Instant_Oracle.aspx


这篇关于如何使用TNSName连接到Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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