private static object CreateObject(DbProviderFactory factory, ProviderSupportedClasses kindOfObject, string providerName)
        {
            switch (kindOfObject)
            {
                case ProviderSupportedClasses.DbConnection:
                    return factory.CreateConnection();

                case ProviderSupportedClasses.DbDataAdapter:
                    return factory.CreateDataAdapter();

                case ProviderSupportedClasses.DbParameter:
                    return factory.CreateParameter();

                case ProviderSupportedClasses.DbCommand:
                    return factory.CreateCommand();

                case ProviderSupportedClasses.DbCommandBuilder:
                    return factory.CreateCommandBuilder();

                case ProviderSupportedClasses.DbDataSourceEnumerator:
                    return factory.CreateDataSourceEnumerator();

                case ProviderSupportedClasses.CodeAccessPermission:
                    return factory.CreatePermission(PermissionState.None);
            }
            throw new InternalException(string.Format(CultureInfo.CurrentCulture, "Cannot create object of provider class identified by enum {0} for provider {1}", new object[] { Enum.GetName(typeof(ProviderSupportedClasses), kindOfObject), providerName }));
        }
예제 #2
0
 /// <summary>
 /// 获取TNS信息
 /// Columns:InstanceName,ServerName,ServiceName,Protocol,Port
 /// </summary>
 /// 需要安装ODP.NET
 /// <returns></returns>
 internal static DataTable GetTNSInstance()
 {
     try
     {
         System.Data.Common.DbProviderFactory factory =
             System.Data.Common.DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
         if (factory.CanCreateDataSourceEnumerator)
         {
             System.Data.Common.DbDataSourceEnumerator dsenum = factory.CreateDataSourceEnumerator();
             return(dsenum.GetDataSources()); //InstanceName,ServerName,ServiceName,Protocol,Port
         }
     }
     catch { }
     return(null);
 }