Oracle Connection in C# - connection string

£可爱£侵袭症+ 提交于 2019-12-11 00:26:37

问题


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

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();

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.


回答1:


My code is now working. I should've read the Oracle documentation (reference below).

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();

Reference: http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/12c/r1/appdev/dotnet/Web_version_Fully_Managed_ODPnet_OBE/odpnetmngdrv.html



来源:https://stackoverflow.com/questions/46408085/oracle-connection-in-c-sharp-connection-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!