I wrote a .Net Windows service to copy data from a 4D database (v12) to a SQL Server database every 4 hours. It is running on Windows 7 32-bit and running as Local System. I am using version 12.02 of the 4D ODBC driver.
When the service 1st runs everything works OK. On its second run the connection to SQL Server still works, but the ODBC connection to 4D gets the following error:
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)
The code is careful to dispose of the connection to both SQL Server and 4D after each run in the following way:
using (_connSQL = new SqlConnection(DataWarehouseCS))
{
_connSQL.Open();
using (_conn4D = new OdbcConnection(4DCS))
{
_conn4D.Open();
Load4DTables();
}
}
Once the error occurs the ODBC connection never works again until I stop/start the service. This will allow it to work again one time. I have tried connecting with a System DSN as well as a DSN-less connection, but the results are the same. I believe if I have the service run more frequently, say once every 10 minutes, it will work more than once, but something must happen when enough time goes by that stops it from working.
I'm very confused about what the problem is. I'd greatly appreciate any help or suggestions to try.