private DbConnection OpenConnection(Sage50ImportDetails importDetails, Sage50Driver sage50Driver) { var connectionString = CreateConnectionString(importDetails, sage50Driver); var conn = new OdbcConnection(connectionString); OpenConnection(conn); return(conn); }
public DbConnection OpenConnection(Sage50ImportDetails importDetails) { var drivers = driverDetector.FindSageDrivers(); var folder = GetFolder(importDetails.DataDirectory); return(OpenConnection(new Sage50ImportDetails { DataDirectory = folder, Password = importDetails.Password, Username = importDetails.Username }, drivers)); }
private DbConnection OpenConnection(Sage50ImportDetails importDetails, IEnumerable <Sage50Driver> drivers) { foreach (var driver in drivers) { try { return(OpenConnection(importDetails, driver)); } catch (CannotOpenDataDirectoryException) { } } throw new IncorrectSage50CredentialsException( "Could not open the specified folder with available versions of Sage 50.\n" + "Check that the folder is a Sage 50 data directory and that the correct version of Sage is installed.\n" + "The data directory can be found by logging in to Sage and clicking help->about from the menu.\n" + "Available versions of Sage 50: " + String.Join(", ", drivers.Select(x => x.FriendlyName))); }
private static string CreateConnectionString(Sage50ImportDetails importDetails, Sage50Driver driver) { var builder = new OdbcConnectionStringBuilder { Driver = driver.Name }; builder["uid"] = importDetails.Username; builder["dir"] = importDetails.DataDirectory; if (!string.IsNullOrEmpty(importDetails.Password)) { builder["pwd"] = importDetails.Password; } var connectionString = builder.ConnectionString; return(connectionString); }