English 中文(简体)
C#方案甲骨质接触
原标题:Oracle access from C# program

I would appreciate any advice to resolve this problem.
I m not a pro developer but a "hobbyist" who has "inherited" a reporting job (thanks to my interest in programming - classic example of never volunteer !).

I m trying to access an Oracle 10g database from C#.
To keep things as simple as possible I ve got a bare WPF form with a single button. Inside the click event of the button, I ve got the following code (which, incidentally worked fine in an earlier program set up on a different PC) -

using System.Data;
using System.Data.OracleClient;

...

string oraStr1 = "Data Source=(DESCRIPTION=(ADDRESS_LIST =(ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=myPort)))(CONNECT_DATA=(SERVICE_NAME=myDB)));Password=myPassword;User ID=myUser;";

DataTable oraTable = new DataTable();
string queryString = "Select surname,forenames from person table where surname =  Smith ";

using ( OracleConnection oraConnect = new OracleConnection( oraStr1 ) )
{
    try
    {
        OracleCommand OraCmd = new OracleCommand( queryString, oraConnect );  
        oraConnect.Open();

        OracleDataAdapter OraAdapter = new OracleDataAdapter();
        OraAdapter.SelectCommand = OraCmd;

        OraAdapter.Fill( oraTable );
    }
    finally
    {
        oraConnect.Close();
    }

Now... the (C# Express Edition) application is running in a VM on a remote server. My share on this VM has also had Oracle Database 10g Client Release 2 (10.2.0.1.0) installed.

此外,还有信息技术安装的Oracle数据存取部分。

邮管处管理ODBCAD32时,没有任何骨质司机被列入名单。

我认为,安装的司机已经失败,这阻碍了我的方案启动任何联系。 然而,我没有证据,并想知道这里的学到的人能否就获得任何东西提出建议?

民主选举学会错误信息的头几个行文如下:

System.Exception was unhandled
Message="OCIEnvCreate failed with return code -1 but error message text was not available."
Source="System.Data.OracleClient"
StackTrace:
     at System.Data.OracleClient.OciHandle..ctor(OciHandle parentHandle, HTYPE handleType, MODE ocimode, HANDLEFLAG handleflags)
     at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
     at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
     at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
     at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
     at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
     at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
     at System.Data.OracleClient.OracleConnection.Open()    

工作寿命要长,但正如你能够看到的那样,这种安排相当复杂......

我没有资格告诉信息技术公司的工作,但会欣赏我能够接过的任何<><>>dvice?

问题回答

I would recommend not going crazy with data providers and custom sql.

找到一个支持Oracle(如NHibernate)的办公室,让它做这项工作。 你的唯一关切是将表格绘制到您的物体上,然后用中性语言(现为荷兰语支持林克语和拉姆布达语,这样它就没有比这更容易。

幸福编码:

ADO。 简而言之,我不会感到惊讶的是,Oracle司机没有在ODBC路口展示——你正在使用OLEDB的连接,而后者是一种不同于ODBC的动物。

它看着你正在使用该系统。 数据:OracleClient, 微软的甲骨质客户,而不是Oracle Corp的客户—— 这一客户被贬低(Microsoft今后不再支持该客户),我不建议你使用该客户。

http://www.carlprothman.net/Default.aspx?tabid=86#acleNETDataProviderFromOracle”rel=“nofollow” http://www.carlprothman.net/Default.aspx?tabid=86#OracleNETDataproviderFromOracle

或在此:

Here are some sample connection strings: http://www.connectionstrings.com/oracle

这里是我如何这样做,但需要找到新的途径,因为OracleClient的一部分在4.0和4.5条中已经过时。

string sqlquery = "select * from person"; 
DataGridView1.DataSource = PullTableResults(sqlquery);

private static DataTable PullTableResults(string sqlquery)
{
   try
   {
       if (showMessages)
       {
           MessageBox.Show(sqlquery);
       iii

       var conn = new OracleConnection(Oradb);
       conn.Open();
       var cmd = new OracleCommand(sqlquery, conn);
       cmd.CommandType = CommandType.Text;
       var dr = cmd.ExecuteReader();
       var read = dr.Read();
       var table = new DataTable();
       var oda = new OracleDataAdapter(cmd);
       int fill = oda.Fill(table);
       conn.Close();
       conn.Dispose();
       return table;
   iii
   catch (Exception ex)
   {
       const string Message = "Database Exception";

       if (showMessages)
       {
           MessageBox.Show(Message + ex);
       iii

       var table = new DataTable();
       return table; // return empty table cause there was error
   iii

iii





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签