Ejemplo n.º 1
0
        private static string GetOleDbConnectionString(string fileNameOrConnectionString)
        {
            if (JetStoreDatabaseHandling.IsConnectionString(fileNameOrConnectionString) &&
                JetConnection.GetDataAccessProviderType(fileNameOrConnectionString) == DataAccessProviderType.OleDb)
            {
                return(fileNameOrConnectionString);
            }

            var filePath         = JetStoreDatabaseHandling.ExpandFileName(JetStoreDatabaseHandling.ExtractFileNameFromConnectionString(fileNameOrConnectionString));
            var connectionString = JetConnection.GetConnectionString(filePath, DataAccessProviderType.OleDb);

            if (JetStoreDatabaseHandling.IsConnectionString(fileNameOrConnectionString) &&
                JetConnection.GetDataAccessProviderType(fileNameOrConnectionString) == DataAccessProviderType.Odbc)
            {
                var oldCsb = new DbConnectionStringBuilder(true)
                {
                    ConnectionString = fileNameOrConnectionString
                };
                var newCsb = new DbConnectionStringBuilder {
                    ConnectionString = connectionString
                };

                newCsb.SetUserId(oldCsb.GetUserId(DataAccessProviderType.Odbc), DataAccessProviderType.OleDb);
                newCsb.SetPassword(oldCsb.GetPassword(DataAccessProviderType.Odbc), DataAccessProviderType.OleDb);
                newCsb.SetSystemDatabase(oldCsb.GetSystemDatabase(DataAccessProviderType.Odbc), DataAccessProviderType.OleDb);
                newCsb.SetDatabasePassword(oldCsb.GetDatabasePassword(DataAccessProviderType.Odbc), DataAccessProviderType.OleDb);

                connectionString = newCsb.ConnectionString;
            }

            return(connectionString);
        }