嗯,问题如下:
我有一个使用C#构建的WPF应用程序,我已经知道如何连接到oracle数据库引擎,但我需要一些帮助。
首先,我想知道如何将服务器添加到连接字符串......
OleDbConnection conn = new OleDbConnection("provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER");
是提供者还是数据源?我应该在服务器上写localhost
或127.0.0.1
然后写入端口?如何添加端口server:port
还是应该添加其他参数?
第二,我创建了一个函数来执行作为参数发送给它的查询,我想将查询结果放在DataSet
但我不知道如何将结果转换为DataSet。
这是我的功能:
public DataSet SelectQuery(String p_sSql)
{
DataSet ds = new DataSet();
try
{
OleDbCommand myOleDbCommand = conn.CreateCommand();
myOleDbCommand.CommandText = p_sSql.ToString();
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
myOleDbDataReader.Read();
//here I want to add the result to the DataSet ds ...
myOleDbDataReader.Close();
conn.Close();
return ds;
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
return null;
}
}
答案 0 :(得分:1)
如果您不仅限于ODBC,则应尝试使用ODP.NET
http://www.oracle.com/technology/tech/windows/odpnet/index.html
这是一个简单的教程
http://www.oracle.com/technology/pub/articles/cook-vs08.html
答案 1 :(得分:0)
有关Oracle连接字符串的示例请查看此URL,因为它将包含所需的所有信息。 connectionstrings.com/oracle。另一方面,除非你真的不需要为ODP.Net提供商打扰,因为安装很麻烦,你将遇到Oracle 10g的x64问题。我发现使用System.Data.OracleClient时遇到的问题较少,不幸的是.Net 4.0中不推荐使用它。
至于指定端口,通常所有信息都在TNS文件中指定,您只需指定要在连接字符串中使用的TNS列表。