c sharp连接oracleconnection数据库代码
时间: 2023-06-04 10:09:00 浏览: 133
以下是C#连接Oracle数据库的代码示例:
using System;
using System.Data;
using Oracle.DataAccess.Client;
class Program
{
static void Main(string[] args)
{
string connString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=database)));User Id=username;Password=password;";
OracleConnection conn = new OracleConnection();
conn.ConnectionString = connString;
try
{
conn.Open();
Console.WriteLine("Connected to Oracle version " + conn.ServerVersion);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
finally
{
conn.Dispose();
}
}
}
阅读全文