コード例 #1
0
ファイル: DataFactory.cs プロジェクト: stphomeboyz/crudwork
        /// <summary>
        /// retrieve a list of service available
        /// </summary>
        /// <param name="databaseProvider"></param>
        /// <returns></returns>
        public static ServiceDefinitionList GetService(DatabaseProvider databaseProvider)
        {
            /*
             * ServerName
             * InstanceName
             * IsClustered
             * Version
             * FactoryName
             *
             */
            string                 providerString  = Providers.ToProvider(databaseProvider);
            DbProviderFactory      providerFactory = DbProviderFactories.GetFactory(providerString);
            DbDataSourceEnumerator enumerator      = providerFactory.CreateDataSourceEnumerator();

            return(enumerator.GetDataSources().ToServiceDefinitionList());
        }
コード例 #2
0
        public static DataTable GetServer()
        {
            try
            {
                DataTable         dt = new DataTable();
                DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");

                if (dbProviderFactory.CanCreateDataSourceEnumerator)
                {
                    DbDataSourceEnumerator dbDataSourceEnumerator = dbProviderFactory.CreateDataSourceEnumerator();

                    if (dbDataSourceEnumerator != null)
                    {
                        dt = dbDataSourceEnumerator.GetDataSources();
                    }
                }
                return(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public IEnumerable <string> Execute(TnsNamesQuery query)
        {
            if (string.IsNullOrEmpty(query.ProviderInvariantName))
            {
                throw new ArgumentNullException(nameof(query.ProviderInvariantName));
            }

            IEnumerable <string> tnsNames = Enumerable.Empty <string>();
            DbProviderFactory    factory  = DbProviderFactories.GetFactory(query.ProviderInvariantName);

            if (factory.CanCreateDataSourceEnumerator)
            {
                DbDataSourceEnumerator dsenum = factory.CreateDataSourceEnumerator();
                if (dsenum != null)
                {
                    DataTable dt   = dsenum.GetDataSources();
                    DataRow[] rows = dt.Select(null, "InstanceName", DataViewRowState.CurrentRows);

                    tnsNames = rows.Select(row => (string)row["InstanceName"]);
                }
            }

            return(tnsNames);
        }
コード例 #4
0
ファイル: adriver.cs プロジェクト: surak8/cs_codegen
        static void testFactory(DbProviderFactory factory)
        {
            StringBuilder sb;
            int           i = 0;

            sb = new System.Text.StringBuilder();
            try {
                //factory.
                var dbcsb = factory.CreateConnectionStringBuilder();
                sb.Append(factory.GetType().Name + ": Keys = ");
                foreach (string akey in dbcsb.Keys)
                {
                    if (i > 0)
                    {
                        sb.Append(",");
                    }
                    sb.Append(akey);
                    //dbcsb.Add(akey, "my_" + akey);
                    i++;
                }
                if (i > 0)
                {
                    sb.AppendLine();
                    Trace.WriteLine(sb.ToString());
                    Trace.WriteLine("Sample connection-string: " + dbcsb.ConnectionString);
                    //Logger.log(sb.ToString());
                }
                else
                {
                    Trace.WriteLine("no keys");
                }

                if (factory.GetType().Equals(typeof(System.Data.SqlClient.SqlClientFactory)))
                {
                    dbcsb.Clear();
                    dbcsb.Add("User ID", "operator");
                    dbcsb.Add("Password", "operator");
                    dbcsb.Add("Application Name", Assembly.GetEntryAssembly().GetName().Name);
                    dbcsb.Add("Workstation ID", Environment.MachineName);
                    dbcsb.Add("Data Source", "colt-sql");
                    dbcsb.Add("Initial Catalog", "checkweigh_data_dev");

                    dbcsb.Add("Persist Security Info", true);
                    dbcsb.Add("Integrated Security", true);
                    Trace.WriteLine("her");
                }
                testConnection(factory, dbcsb.ConnectionString);

                var x1 = factory.CreateCommand();
                //x1.
                var x2 = factory.CreateCommandBuilder();
                var x4 = factory.CreateConnectionStringBuilder();
                var x5 = factory.CreateDataAdapter();
                if (factory.CanCreateDataSourceEnumerator)
                {
                    var x6 = factory.CreateDataSourceEnumerator();
                    Trace.WriteLine("do-enumerator here");
                }
                var x7 = factory.CreateParameter();
            } catch (Exception ex) {
                // Set the connection to null if it was created.
                //if (connection != null) {
                //    connection = null;
                //}
                Console.WriteLine(ex.Message);
            }
        }
コード例 #5
0
 /// <summary>
 /// Provides a mechanism for enumerating all available instances of database servers within the local network
 /// </summary>
 /// <returns>Returns a new instance of <see cref="DbDataSourceEnumerator"/> created by the current <see cref="DbProviderFactory"/></returns>
 public DbDataSourceEnumerator GetDataSourceEnumerator()
 {
     //Return this back to the caller
     return(_dbProviderFactory.CreateDataSourceEnumerator());
 }
コード例 #6
0
 /// <summary>
 /// Returns a new instance of the provider's class that implements the <see cref="T:System.Data.Common.DbDataSourceEnumerator"></see> class.
 /// </summary>
 /// <returns>
 /// A new instance of <see cref="T:System.Data.Common.DbDataSourceEnumerator"></see>.
 /// </returns>
 public override DbDataSourceEnumerator CreateDataSourceEnumerator()
 {
     return(m_underlyingFactory.CreateDataSourceEnumerator());
 }
コード例 #7
0
 /// <inheritdoc />
 public override DbDataSourceEnumerator CreateDataSourceEnumerator()
 {
     return(_underlyingProvider.CreateDataSourceEnumerator());
 }