zoukankan      html  css  js  c++  java
  • OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用 问题处理

    OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用 问题处理如下:

    解决方法一:更换连接方式

     config 文件配置:

    <add name="MASTER_DB" connectionString="Provider=MSDAORA;Data Source=jhemr;Password=jhemr;User ID=jhemr;" providerName="System.Data.OleDb"/>

    对应的C#程序(需要加入using System.Data.OleDb;)

     public DataSet GetDBDataSet(string DBType, string cmdtxt)
            {
                DataSet dsOrder = new DataSet();
    
                ConnectionStringSettings sDB = ConfigurationManager.ConnectionStrings[DBType];
              
                if (sDB.ProviderName == "System.Data.OracleClient")
                {
                    DbProviderFactory fDB = DbProviderFactories.GetFactory(sDB.ProviderName);
                    #region OracleClient
                    using (DbConnection connDB = fDB.CreateConnection())
                    {
                        connDB.ConnectionString = sDB.ConnectionString;
                        try
                        {
                            connDB.Open();
                            DbCommand cmdDB = connDB.CreateCommand();
                            cmdDB.CommandText = cmdtxt;
                            DbDataAdapter da = fDB.CreateDataAdapter();
                            da.SelectCommand = cmdDB;
                            da.Fill(dsOrder);
                            cmdDB.Connection.Close();
                        }
                        catch (Exception ex)
                        {
                            if (connDB.State == ConnectionState.Open)
                                connDB.Close();
                            throw ex;
                        }
                    }
                    #endregion
                }
                else if (sDB.ProviderName == "System.Data.OleDb")
                {
                    string connectionString = sDB.ConnectionString;
                    using (OleDbConnection connection = new OleDbConnection(connectionString))
                    {
                        try
                        {
                            connection.Open();
                            OleDbCommand command = new OleDbCommand();
                            command.Connection = connection;
                            command.CommandText = cmdtxt;
                            OleDbDataAdapter adapter = new OleDbDataAdapter(command);
                            adapter.Fill(dsOrder, "dsOrder");
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            if (connection.State != ConnectionState.Closed)
                            {
                                connection.Close();
                            }
                        }
    
                    }
                }
              
                return dsOrder;
            }
  • 相关阅读:
    【洛谷P2839】middle
    【洛谷P2495】消耗战
    【CF1438D】Powerful Ksenia
    【CF878E】Numbers on the blackboard
    【洛谷U138580】简单的打击
    【洛谷P4774】屠龙勇士
    【GMOJ5363】生命之树
    【YbtOJ#20075】区间异或
    【YbtOJ#20077】计划带师
    hdu 2688
  • 原文地址:https://www.cnblogs.com/mengzhixingping/p/10133121.html
Copyright © 2011-2022 走看看