If you need to support both Advantage 7 and 8 with .net 2.0 code you probably want to look at the DbProviderFactory. That way you can make use of the .Net dataprovider for .net 2.0 for 8.0 and if you connect to 7.0 you can use the OLE Db driver.
You might also want to use the DbConnectionStringBuilder to build the connection string.
Here is some example code for creating the Connection and Parameter objects. Commands can be created from the Connection objects.
public DbConnection GetConnection()
factory = "System.Data.OleDb";
_connectionType = "ADS_REMOTE_SERVER|ADS_LOCAL_SERVER";
tableType = "ADS_CDX";
factory = "Advantage.Data.Provider";
_connectionType = "local|remote";
tableType = "CDX";
_factory = DbProviderFactories.GetFactory(factory);
DbConnectionStringBuilder builder = _factory.CreateConnectionStringBuilder();
builder["ServerType"] = _connectionType;
builder["Data Source"] = _datapath;
builder["CharType"] = _chartype;
builder["FilterOptions"] = "RESPECT_WHEN_COUNTING";
builder["TrimTrailingSpaces"] = true;
builder["TableType"] = tableType;
con = _factory.CreateConnection();
con.ConnectionString = builder.ConnectionString;
public DbParameter CreateParameter(string name, object value)
DbParameter param = _factory.CreateParameter();
param.ParameterName = name;
param.Value = value;
The downside of using the DbProviderFactory is that the .Net data provider must be installed into the GAC and the factories xml file. The Advantage installer only works on machines with Visual Studio installed as well (currently) so it’s not much use when deploying to a server. This means that you have to install by hand (copying over gacutil by hand) or create your own installer that does all the hardwork. Neither are particularly ideal. I’ve yet to figure out how to use Wix or the Visual Studio installer projects to install into the .net 2.0 GAC properly.
The other downside of using the factory is that you can only use the lowest common denominator of functions. You have to give up the more advanced methods and parameters provided by the Advantage library. Well ‘have’ is a strong word, you can cast the Db* objects to their actual type and then use the more advanced methods but there is more work involved. You need to check the actual type of the object, then cast it and then use it. That also means that you must have a direct reference to the Assembly – even if you aren’t using it at that site. In other words a site running ADS 7.0 would still have t o have the version 8.0 drivers installed.