c# oracle datasource,OracleConnectionStringBuilder

获取或设置要连接到的 Oracle 数据源的名称。Gets or sets the name of the Oracle data source to connect to.

public:

property System::String ^ DataSource { System::String ^ get(); void set(System::String ^ value); };

public string DataSource { get; set; }

member this.DataSource : string with get, set

Public Property DataSource As String

属性值

为 DataSource 属性的值,或者,如果未提供任何值,则为 Empty。The value of the DataSource property, or Empty if none has been supplied.

示例

下面的示例演示 OracleConnectionStringBuilder 类将 "数据源" 连接字符串密钥的同义词转换为众所周知的键。The following example demonstrates that the OracleConnectionStringBuilder class converts synonyms for the "Data Source" connection string key into the well-known key.

// You may need to set a reference to the System.Data.OracleClient

// assembly before you can run this sample.

using System.Data.OracleClient;

class Program

{

static void Main()

{

OracleConnectionStringBuilder builder =

new OracleConnectionStringBuilder(

"Server=OracleDemo;Integrated Security=True");

// Display the connection string, which should now

// contains the "Data Source" key, as opposed to the

// supplied "Server".

Console.WriteLine(builder.ConnectionString);

// Retrieve the DataSource property.

Console.WriteLine("DataSource = " + builder.DataSource);

Console.WriteLine("Press any key to continue.");

Console.ReadLine();

}

}' You may need to set a reference to the System.Data.OracleClient

' assembly before running this example.

Imports System.Data.OracleClient

Module Module1

Sub Main()

Dim builder As _

New OracleConnectionStringBuilder( _

"Server=OracleDemo;Integrated Security=True")

' Display the connection string, which should now

' contains the "Data Source" key, as opposed to the

' supplied "Server".

Console.WriteLine(builder.ConnectionString)

' Retrieve the DataSource property.

Console.WriteLine("DataSource = " & builder.DataSource)

Console.WriteLine("Press any key to continue.")

Console.ReadLine()

End Sub

End Module

注解

此属性对应于连接字符串中的 "数据源" 和 "服务器" 键。This property corresponds to the "Data Source" and "Server" keys within the connection string. 无论在提供的连接字符串中提供了哪些值,由创建的连接字符串 OracleConnectionStringBuilder 将使用众所周知的 "数据源" 键。Regardless of which of these values has been supplied within the supplied connection string, the connection string created by the OracleConnectionStringBuilder will use the well-known "Data Source" key. 如果在您尝试设置此属性时传入的值为 null,则将重置 DataSource 属性。If the value passed in is null when you try to set the property, the DataSource property is reset. 如果尚未设置值,而开发人员尝试检索属性,则返回值为 Empty 。If the value has not been set and the developer tries to retrieve the property, the return value is Empty.

适用于

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是C#连接Oracle数据库的示例代码: ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using Oracle.DataAccess.Client; namespace OracleDemo { class Program { static void Main(string[] args) { string connStr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=scott;Password=tiger"; using (OracleConnection conn = new OracleConnection(connStr)) { try { conn.Open(); OracleCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM emp"; OracleDataAdapter adapter = new OracleDataAdapter(cmd); DataSet ds = new DataSet(); adapter.Fill(ds); foreach (DataRow row in ds.Tables[0].Rows) { Console.WriteLine(row["empno"] + "\t" + row["ename"] + "\t" + row["job"] + "\t" + row["mgr"] + "\t" + row["hiredate"] + "\t" + row["sal"] + "\t" + row["comm"] + "\t" + row["deptno"]); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } } Console.ReadLine(); } } } ``` 在这个示例中,需要引用Oracle.DataAccess.dll库。您可以通过NuGet包管理器安装Oracle.ManagedDataAccess或Oracle.ManagedDataAccess.Core包,也可以手动安装Oracle客户端并添加Oracle.DataAccess.dll引用。 在连接字符串中,需要替换主机名、端口、服务名、用户名和密码为您的实际值。 示例中使用OracleCommand和OracleDataAdapter来执行查询并获取数据。通过DataSet可以方便地处理数据并进行输出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值