Tutorial :Jet 4.0 connection problem with c# windows application



Question:

I am developing a win .net application which runs continuously in server machine. Application will get connected with access(mdb) databases resided in several client machines using Jet 4.0 OLEDB provider.

Each connected database was already in use by some other application installed locally.

My app successfully communicates with all the databases when client machines are constantly alive.

But if one of my client machine goes down(say system or network) and rebooted, application cannot reconnect to that specific database, though it is accessible via network.

Even i tried to restart my application programmatically to re-establish the connection. But, It also fails.

Application just throws

"Disk or Network error"

or

"Unspecified Error"

or

"Cannot start your application. The workgroup information file is missing or opened exclusively by another user."

Anyone?


Solution:1

Yes.

Actually, I'm using static object with the following piece of code for each of the databases associated with the application.

DbProviderFactory factory;  DbConnection connection;  DbDataAdapter dataAdapter;    void SetConnection(ConnectionStringSettings settings) {      factory = DbProviderFactories.GetFactory(settings.ProviderName);      if (factory != null) {          if (connection == null) {              connection = factory.CreateConnection();              dataAdapter = factory.CreateDataAdapter();                                  connection.ConnectionString = settings.ConnectionString;          }      }  }    public DataTable GetTable(string statement) {      DataTable dataTable = null;      if (connection != null) {         dataAdapter.SelectCommand = connection.CreateCommand();         dataAdapter.SelectCommand.CommandText = statement;         dataTable = new DataTable();         dataAdapter.Fill(dataTable);      }      else         throw new Exception("Connection object null");        return dataTable;  }  

I am setting the connection string and provider name from the app.config.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »