C# 中的 Oracle 连接 - 连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46408085/
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
Oracle Connection in C# - connection string
提问by Fen Ignacio
I'm currently trying to build an application in C# and connecting it to a live db running in Oracle 11g. I have the following connection details
我目前正在尝试用 C# 构建一个应用程序,并将其连接到在 Oracle 11g 中运行的实时数据库。我有以下连接详细信息
Host IP: 10.204.1.3
Port: 1521
DB Name: PROD
My source code
我的源代码
string connString = "DATA SOURCE=10.204.1.3:1521/PROD;PERSIST SECURITY" +
"INFO=True;USER ID=username; PASSWORD=userpass";
OracleConnection conn = new OracleConnection(connString);
conn.Open();
I was able to add a connection in Server Explorer with the Connection String used by VS but is having the error below in conn.Open();
我能够使用 VS 使用的连接字符串在服务器资源管理器中添加连接,但在 conn.Open(); 中出现以下错误;
An unhandled exception of type 'System.NullReferenceException' occurred in
Oracle.DataAccess.dll
Sorry if this is a basic question, I'm new in VS, and Oracle and can't find the solution in the other part of the web. Thanks in advance.
抱歉,如果这是一个基本问题,我是 VS 和 Oracle 的新手,无法在网络的其他部分找到解决方案。提前致谢。
采纳答案by Fen Ignacio
My code is now working. I should've read the Oracle documentation (reference below).
我的代码现在正在运行。我应该阅读 Oracle 文档(参考如下)。
string connString = "DATA SOURCE=10.204.3.1:1521/PROD;" +
"PERSIST SECURITY INFO=True;USER ID=username; password=password; Pooling
=False;";
OracleConnection conn = new OracleConnection();
conn.ConnectionString = connString;
conn.Open();
参考:http: //www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/appdev/dotnet/Web_version_Fully_Managed_ODPnet_OBE/odpnetmngdrv.html