The LJCDataAccess.DataAccess class is capable of connecting using the SQL Server data provider, OLEDB driver, ODBC driver or MySQL data provider.
DataAccess configuration can be defined externally in file DataConfigs.xml
This is an example of a DataConfigs.xml file.
<?<xml version="1.0" ?> <DataConfigs> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <DataConfig>; <Name>ConfigName</Name> <ConnectionTypeName>SQLServer</Name> <DbServer>DataServerName</DbServer> <Database>DatabaseName</Database> </DataConfig> </DataConfigs>
The available ConnectionTypeNames are: "SQLServer", "OLEDB", "ODBC", "MySQL" and "Access".
The DbServer is the "Server Name" that is displayed when you connect to the service Using SQL Server Management Studio.
The DataConfigs.xml file must be in the folder where the calling program is located.
This is an example of a ConnectionTemplates.xml file.
<?<xml version="1.0" ?> <ConnectionTemplates> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ConnectionTemplate> <Name>SQLServer</Name> <Template>Data Source={DbServer}; Initial Catalog={Database}; Integrated Security=True; User Id={UID} Password={PSWD};</Template> </ConnectionTemplate> <ConnectionTemplate> <Name>MySQL</Name> <Template>server={DbServer}; UserId={UID}; Password={PSWD}; database={Database};</Template> </ConnectionTemplate> </ConnectionTemplates>
The "Name" value matches the "ConnectionTypeName" from the DataConfig definition.
The template replaceable values: {DbServer}, {Database}, {UID} and {PSWD} also come from the DataConfig definition.
The complete ConnectionTemplates.xml file is in the LJCDataAccessConfig project. This file must be in the folder where the calling program is located.
using LJCDataAccess; using LJCDataAccessConfig; // Create DataAccess object. private static DataAccess CreateDataAccess() { // Get the DataConfig definition. DataConfigs dataConfigs = new DataConfigs(); dataConfigs.LJCLoadData(); dataConfig = dataConfigs.LJCGetByName("ConfigName"); // Create the DataAccess object. var connectionString = dataConfig.GetConnectionString(); var providerName = dataConfig.GetProviderName(); var retValue = new DataAccess(connectionString, providerName); return retValue; }