连接到Oracle数据库,未tnsname.ora中 [英] Connect to Oracle without tnsname.ora
本文介绍了连接到Oracle数据库,未tnsname.ora中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从我的.NET应用程序连接到Oracle。
I need to connect to oracle from my .Net application.
我想用 ODP.NET
有没有办法连接到Oracle数据库,未对的tnsnames.ora
提交任何依赖性?原因我想问的是,因为我将有数百种不同的连接,我不会要依赖于该文件。
Is there a way to connect to Oracle without any dependency on the tnsnames.ora
file? Reason I ask is because I'll have hundreds of different connections and I wouldnt want to be dependant on that file.
推荐答案
是的,如果你使用包含的tnsname.ora
的数据连接字符串。
Yes, if you use a connection string that contains the data of tnsname.ora
.
假设你的tnsname条目是这样的:
Say your tnsname entry looks like this:
YourTnsName =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = YourHost)(PORT = 1521))
)
(CONNECT_DATA =
(SID = YourSid)
)
)
而不是在连接字符串中使用 YourTnsName
,你可以写这样的:
instead of using YourTnsName
in the connection string, you can write it like this:
var constr = new OracleConnectionStringBuilder()
{
DataSource = @"(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = YourHost)(PORT = 1521)))(CONNECT_DATA =(SID = YourSid)))",
UserID = "userid",
Password = "password",
}.ConnectionString;
using (var con = new OracleConnection(constr))
{
...
}
因此,在没有进入的tnsname.ora
是必要的。
这篇关于连接到Oracle数据库,未tnsname.ora中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文