C#中的Oracle Connection-连接字符串 [英] Oracle Connection in C# - connection string

查看:1842
本文介绍了C#中的Oracle Connection-连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试使用C#构建应用程序并将其连接到在Oracle 11g中运行的实时数据库. 我有以下连接详细信息

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

我能够使用VS使用的连接字符串在Server Explorer中添加连接,但是在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

很抱歉,如果这是一个基本问题,我是VS和Oracle的新手,无法在网络的其他部分找到解决方案.提前致谢.

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.

推荐答案

我的代码正在运行.我应该阅读Oracle文档(下面参考).

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

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

这篇关于C#中的Oracle Connection-连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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