程序運行過程當中遇到「ORA-03114: not connected to ORACLE」的問題解決

c#,winform程序,數據批量入oracle庫時用到DataAdaper的.FillSchema函數,如:da.FillSchema(dt2, SchemaType.Mapped);數據庫

程序運行一段時間後在此出現中斷,錯誤提示:ORA-03114: not connected to ORACLE。c#

經從網上查找相關解決方案,有說重啓應用程序的;有說這是此函數自己的一個bug,須要添加什麼微軟官方所說的解決方案的。服務器

經本人試驗,重啓應用程序是會變好。可是運行過程當中還會不免出現上面的錯誤,這時候就還須要重啓程序,因此並非長久之計。網絡

後經試驗,只在數據庫服務一停,上述問題一定會出現。也就是說只要出現過數據庫鏈接斷開的狀況(好比數據庫服務器斷電致使網絡斷開,從而程序中鏈接數據庫的地方中斷),那麼即便後面數據庫與程序鏈接又能夠恢復正常,那麼此處仍是會報ORA-03114: not connected to ORACLE的錯誤。說明數據庫鏈接仍不可用。oracle

並且經查DataAdapter.FillSchema()函數官方文檔:The connection object associated with the SelectCommand must be valid,but it does not need to be open. If the connection is closed before FillSchema is called, it is opened to retrieve data and then closed. If the connection is open before FillSchema is called, it remains open.app

說明此函數運行時,必須保證數據庫鏈接可用,並且函數自己自動會打開鏈接,用而後再關閉。若是自己就是打開狀態,那仍會保持打開狀態不變。函數

經調試試驗,改成以下方案:調試

try
{
da.FillSchema(dt2, SchemaType.Mapped);
}
catch (OracleException ex)
{
try{
cnnOracle = new OracleConnection(strCnnOracle);//strCnnOracle爲數據庫鏈接字符串。
cnnOracle.Open();
}
catch(OracleException ex2)
{
return  ex2.Message;
}
}orm

也就是說,增長了try catch,在catch中從新實例化鏈接,並將鏈接打開便可。ci

相關文章
相關標籤/搜索