Beispiel #1
0
        public void RemoveDatabase(string name)
        {
            OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance;
            DatabaseParam dBParam = ConfigStringsFactory.NewDatabaseParam();

            var connectionString = string.Format(ConnectionString, dBParam.ServerName, dBParam.DatabaseName, dBParam.UserId, dBParam.Password);

            using (IDbConnection con = connectionString.OpenDbConnection())
            {
                int        exist = con.Scalar <int>(string.Format(DatabaseSelectSql, name));
                IDbCommand cmd   = con.CreateCommand();
                if (exist > 0)
                {
                    ///杀死所有连接
                    List <SpWho> spWhoes = con.SqlList <SpWho>(" sp_who ;");
                    foreach (var item in spWhoes)
                    {
                        if (item.dbname == name)
                        {
                            cmd.CommandText = string.Format(DatabaseKillSql, item.spid);
                            cmd.ExecuteNonQuery();
                        }
                    }

                    ///删除数据库
                    cmd.CommandText = string.Format(DatabaseDeleteSql, name);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Beispiel #2
0
        public void CreateDataBase(string name)
        {
            OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance;
            DatabaseParam dBParam = ConfigStringsFactory.NewDatabaseParam();

            var connectionString = string.Format(ConnectionString, dBParam.ServerName, dBParam.DatabaseName, dBParam.UserId, dBParam.Password);

            dBParam.DatabaseName = name;

            using (IDbConnection con = connectionString.OpenDbConnection())
            {
                con.ExecuteNonQuery(string.Format(DatabaseCreateSql,
                                                  dBParam.DatabaseName,
                                                  dBParam.DataFileSize,
                                                  dBParam.DataFileGrowth,
                                                  dBParam.LogFileSize,
                                                  dBParam.LogFileGrowth,
                                                  dBParam.Path));
            }
        }
Beispiel #3
0
        public void CopyData <T>(string datasource)
        {
            OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance;

            var       connectionString = string.Format(ConfigStringsFactory.NewConfigStrings().IHPMSConnectionString, "");
            IRoadsDao roadDao          = MyApp.Dal.RoadsDao;

            roadDao.DataSource = datasource;

            using (IDbConnection sourceConn = connectionString.OpenDbConnection())
            {
                List <T> data = sourceConn.Select <T>();

                if (data.Count > 0)
                {
                    using (IDbConnection targetConn = roadDao.IHPMS.OpenDbConnection())
                    {
                        targetConn.InsertAll <T>(data);
                    }
                }
            }
        }
Beispiel #4
0
 public RoadsDao()
 {
     _configStrings = ConfigStringsFactory.NewConfigStrings();
 }