public void CreateConnection_FromJSON_ToSqlServer()
        {
            var connectionString = jsonDataReader.GetConnectionString("C:\\Users\\connection.json");
            var dbConnection     = dbConnectionFactory.CreateDbConnection(DataBaseType.SqlServer, connectionString);

            Assert.IsNotNull(dbConnection);
        }
 public Feature[] Read(Envelope envelope)
 {
     if (_reader == null)
     {
         Init();
     }
     if (_reader == null)
     {
         return(null);
     }
     try
     {
         using (IDbConnection dbConn = DbConnectionFactory.CreateDbConnection(_connstring))
         {
             if (dbConn == null)
             {
                 return(null);
             }
             dbConn.Open();
             return(_reader.Read(envelope, dbConn));
         }
     }
     catch (Exception ex)
     {
         Log.WriterException(ex);
         return(null);
     }
 }
Example #3
0
        private string GetTablenameById(string fetclassId)
        {
waitLine:
            using (IDbConnection dbConn = DbConnectionFactory.CreateDbConnection(_args))
            {
                if (dbConn == null)
                {
                    goto waitLine;
                }
                dbConn.Open();
                using (IDbCommand cmd = dbConn.CreateCommand())
                {
                    cmd.CommandText = "select datatable from " + BudGISMetadata.cstFeatureClassTableName + " where id='" + fetclassId + "'";
                    using (IDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            string dt = dr.IsDBNull(0) ? null : dr.GetString(0);
                            return(dt);
                        }
                    }
                }
            }
            return(null);
        }
Example #4
0
 public bool TryConnection()
 {
     try
     {
         IDbConnection conn = DbConnectionFactory.CreateDbConnection(_connectionString);
         if (conn == null)
         {
             return(false);
         }
         try
         {
             conn.Open();
             return(true);
         }
         finally
         {
             conn.Close();
             conn.Dispose();
         }
     }
     catch (Exception ex)
     {
         MsgBox.ShowError(ex.Message);
     }
     return(false);
 }
Example #5
0
 public CatalogEntityClassBase(string connString)
 {
     _dbConnection = DbConnectionFactory.CreateDbConnection(connString);
     _dbConnection.Open();
     _connString = connString;
     _adapter    = DiffDbAdapterFactory.GetDiffDbAdapter(_dbConnection);
 }
Example #6
0
 //public EfCoreDbContext()
 //{
 //    Database.EnsureCreated();
 //}
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (!optionsBuilder.IsConfigured)
     {
         optionsBuilder.UseSqlServer(DbConnectionFactory.CreateDbConnection(DatabaseType.SqlServer));
         //optionsBuilder.UseLazyLoadingProxies();//启用EFCore的延迟加载(建议不启用,显式Includ)
     }
 }
        private DbConnection CreateDbConnection()
        {
            var locker = lockObject;

            lock (locker)
            {
                var _dbConnection = DbConnectionFactory.CreateDbConnection(DataBaseType.MySql);
                _dbConnection.ConnectionString = this.ConnectionString;
                _dbConnection.Open();
                return(_dbConnection);
            }
        }
Example #8
0
 private string[] GetFieldsBySpatialFetClass(SpatialFeatureClass spatialFeatureClass)
 {
     using (IDbConnection dbConn = DbConnectionFactory.CreateDbConnection(_connectionString))
     {
         dbConn.Open();
         DiffDbAdapter             _adapter   = DiffDbAdapterFactory.GetDiffDbAdapter(dbConn);
         string                    shapeField = null;
         string                    oidfield   = null;
         Dictionary <string, Type> fields     = _adapter.GetFieldsOfTable(dbConn, spatialFeatureClass.DataTable, out shapeField, out oidfield);
         return(fields.Keys.ToArray());
     }
 }
 private void Init()
 {
     using (IDbConnection dbConn = DbConnectionFactory.CreateDbConnection(_connstring))
     {
         if (dbConn == null)
         {
             return;
         }
         dbConn.Open();
         _reader = new VectorFeatureSpatialDbReader(dbConn, _datatable);
     }
 }
Example #10
0
 public override object GetValue(object sender)
 {
     using (frmNewSpatialDbConn frm = new frmNewSpatialDbConn())
     {
         if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             string connString = frm.GetConnString();
             return(DbConnectionFactory.CreateDbConnection(connString));
         }
     }
     return(null);
 }
Example #11
0
        private bool Test()
        {
            string connString = GetConnString();

            try
            {
                using (IDbConnection conn = DbConnectionFactory.CreateDbConnection(connString))
                {
                    conn.Open();
                    MsgBox.ShowInfo("测试连接成功。");
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowError("测试连接失败:" + ex.Message);
            }
            return(false);
        }
Example #12
0
 public FetClassWriterDb(ICatalogItem locationItem)
 {
     if (locationItem is CatalogDatabaseConn)
     {
         _dbConn = DbConnectionFactory.CreateDbConnection(((locationItem as CatalogDatabaseConn).Tag as SpatialDatabaseConn).ConnectionString);
     }
     else if (locationItem is CatalogFeatureDataset)
     {
         CatalogFeatureDataset cfd = locationItem as CatalogFeatureDataset;
         SpatialFeatureDataset sfd = cfd.Tag as SpatialFeatureDataset;
         _dbConn        = DbConnectionFactory.CreateDbConnection((sfd as CatalogEntityBase)._connString);
         _datasetId     = sfd.Id;
         _dstSpatialRef = SpatialReferenceFactory.GetSpatialReferenceByWKT(sfd.SpatialRef, enumWKTSource.EsriPrjFile);
     }
     else
     {
         throw new NotSupportedException("类型为\"" + locationItem + "\"的位置暂不支持写。");
     }
     _adapter = DiffDbAdapterFactory.GetDiffDbAdapter(_dbConn);
     _dbConn.Open();
 }
Example #13
0
        public void OpenDbConnection()
        {
            var connection = _connectionFactory.CreateDbConnection();

            connection.Open();
        }
 protected DapperRepositoryBase()
 {
     _dbConnection = DbConnectionFactory.CreateDbConnection(DatabaseType.SqlServer);
 }