OCIEnvCreate 失敗,返回程式碼為 -1,但錯誤訊息文字不可用 問題處理
阿新 • • 發佈:2018-12-17
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(stringDBType, 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; }