我編寫了一個.Net Windows服務,每4小時將數據從4D數據庫(v12)複製到SQL Server數據庫。它在Windows 7 32位上運行並以本地系統運行。我正在使用4D ODBC驅動程序的12.02版。Windows服務中的ODBC連接在第二次連接嘗試時失敗
服務第一次運行時,一切正常。在其第二次運行到SQL Server的連接仍然有效,但ODBC連接到4D得到以下錯誤:
System.Data.Odbc.OdbcException (0x80131937): ERROR [08001] Client unable to establish connection: Is the SQL Se at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) at System.Data.Odbc.OdbcConnectionOpen..ctor(OdbcConnection outerConnection, OdbcConnectionString connectionOptions) at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.Odbc.OdbcConnection.Open() at DataWarehouseLoader.DAL.DWGenerator.Run() at DataWarehouseSvc.DataWarehouseSvc.OnTimerElapsed(Object sender, ElapsedEventArgs e)
的代碼是謹慎處置在每次運行後,連接到SQL Server和4D的下列方式:
using (_connSQL = new SqlConnection(DataWarehouseCS))
{
_connSQL.Open();
using (_conn4D = new OdbcConnection(4DCS))
{
_conn4D.Open();
Load4DTables();
}
}
一旦錯誤發生ODBC連接永遠不會再工作,直到我停止/啓動服務。這將允許它再次運行一次。我曾嘗試使用System DSN以及DSN-less連接進行連接,但結果相同。我相信,如果我的服務更頻繁地運行,例如每10分鐘運行一次,它將運行不止一次,但是如果足夠的時間過去了,就會發生一些事情,導致運行停止。
我對這個問題很困惑。我非常感謝任何幫助或建議嘗試。