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; }