我的應用程序通過他們的.net提供程序(FP5)與IBM DB2協同工作。當我很長一段時間,之後離開應用程序試圖從數據庫 - 我碰到下面的錯誤得到任何東西:IBM.Data.DB2.DB2Exception:錯誤[08001] [IBM] SQL30081N檢測到通信錯誤。
---> IBM.Data.DB2.DB2Exception: ERROR [08001] [IBM] SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "SERVER_IP". Communication function detecting the error: "recv". Protocol specific error code(s): "10054", "*", "0". SQLSTATE=08001
我使用實體框架,數據庫和崩潰操作我總是有下列前溝通代碼:
using (EEntities db = EntitiesFactory.CreateEEntity())
{
// ..some operations
}
其中:
public static EEntities CreateEEntity()
{
if (!string.IsNullOrEmpty(GlobalCommon.DBConnectionString))
return CreateEEntity(GlobalCommon.DBConnectionString);
return new EEntities();
}
public static EEntities CreateEEntity(string connectionString)
{
return new EEntities(connectionString);
}
和:
public static string DBConnectionString
{
get
{
if (!string.IsNullOrWhiteSpace(_DBConnectionString))
return _DBConnectionString;
string providerConnectionString = "Database=" +
Settings.Default.DBDatabase + ";User ID=" +
DBUserID + ";Password=" +
DBPassword + ";Server=" +
DBServer + ";Max Pool Size=150;Min Pool Size=15;Connection Lifetime=80;Pooling=true;";
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder =
new EntityConnectionStringBuilder();
//Set the provider name.
entityBuilder.Provider = "IBM.Data.DB2";
// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerConnectionString;
// Set the Metadata location.
entityBuilder.Metadata = @"res://*/DAL.DBModel.csdl|
res://*/DAL.DBModel.ssdl|
res://*/DAL.DBModel.msl";
_DBConnectionString = entityBuilder.ToString();
return _DBConnectionString;
}
set
{
_DBConnectionString = value;
}
}
因此,我認爲如果連接終止,我總是使用以下幾行重新連接。
Pooling或連接生存期有問題嗎?
但是如何重新連接?..如果我打電話使用(EEntities db = EntitiesFactory.CreateEEntity())又不是說它重新連接? – 0x49D1
似乎有些人在EntitesFactory中創建了一個EntityConnection對象 - 您可以檢查該對象的State屬性,以查看連接是否仍然打開,並在適當情況下調用Open方法重新連接。 –
好的,我會盡力的,謝謝。 – 0x49D1