. Net operations on mssql (backup, restore, get table data, get table field information), mssql Field
# Region database management // <summary> // restore and restore the database // </summary> // <param name = "FilePath"> Save path </param> /// <returns> </returns> public bool DataRestore (string FilePath) {string [] Connection = ConfigHelper. getdeleetask( "SqlServer_WYL_DB "). split (';'); SqlServerBackup sqlserverbackup = new SqlServerBackup (); sqlserverbackup. server = Connection [0]. substring (7); sqlserverbackup. database = Connection [1]. substr Ing (9); sqlserverbackup. uid = Connection [2]. substring (4); sqlserverbackup. pwd = Connection [3]. substring (4); if (sqlserverbackup. dbRestore (FilePath) return true; else return false ;} /// <summary> /// back up the database /// </summary> /// <param name = "FilePath"> storage path </param> /// <returns> </returns> public bool DataBackups (string FilePath) {try {string [] Connection = ConfigHelper. getdeleetask( "SqlServer_WYL _ DB "). split (';'); SqlServerBackup sqlserverbackup = new SqlServerBackup (); sqlserverbackup. server = Connection [0]. substring (7); sqlserverbackup. database = Connection [1]. substring (9); sqlserverbackup. uid = Connection [2]. substring (4); sqlserverbackup. pwd = Connection [3]. substring (4); if (sqlserverbackup. dbBackup (FilePath) return true; else return false;} catch (Exception) {return false ;}/// <s Ummary> /// Add a Database Backup Recovery record /// </summary> /// <param name = "Type"> Type: backup and recovery </param> /// <param name = "File"> File name </param> /// <param name = "Size"> File Size </param> /// <param name = "CreateUserName"> create a user </param> /// <param name = "DB"> database </param> /// <param name = "Memo"> remarks </param> // <returns> </returns> public void Add_Backup_Restore_Log (string Type, string File, string Size, string CreateUserName, string DB, str Ing Memo) {LogHelper Logger = new LogHelper ("Backup_Restore_Log"); Hashtable ht = new Hashtable (); StringBuilder sb = new StringBuilder (); sb. append (Type + "consumer"); sb. append (File + "success"); sb. append (Size + "batch"); sb. append (CreateUserName + "external"); sb. append (DB + "databases"); sb. append (Memo + "external"); sb. append (DateTime. now + "success"); sb. append ("∮"); Logger. writeLog (sb. toString () ;}/// <summary> /// database backup and restoration record /// </Summary> // <returns> </returns> public DataTable GetBackup_Restore_Log_List () {LogHelper Logger = new LogHelper ("Backup_Restore_Log"); string filepath = ConfigHelper. getreceivetask( "LogFilePath") + "/Backup_Restore_Log.log"; StreamReader sr = new StreamReader (filepath, Encoding. getEncoding ("UTF-8"); // get the txt file encoding string [] strvalue = sr. readToEnd (). toString (). split ('#'); sr. close (); DataTable dt = New DataTable (); dt. columns. add ("Backup_Restore_Type", Type. getType ("System. string "); dt. columns. add ("Backup_Restore_File", Type. getType ("System. string "); dt. columns. add ("Backup_Restore_Size", Type. getType ("System. string "); dt. columns. add ("CreateUserName", Type. getType ("System. string "); dt. columns. add ("Backup_Restore_DB", Type. getType ("System. string "); dt. columns. add ("Backup_Restore_Memo ", Type. getType ("System. string "); dt. columns. add ("CreateDate", Type. getType ("System. string "); foreach (string item in strvalue) {if (item. length> 6) {string [] str_item = item. split ('signature'); DataRow row = dt. newRow (); string [] Typeitem = str_item [0]. split (']'); row ["Backup_Restore_Type"] = Typeitem [1]. trim (); row ["Backup_Restore_File"] = str_item [1]; row ["Backup_Restore_Size"] = str_item [2]; row ["C ReateUserName "] = str_item [3]; row [" Backup_Restore_DB "] = str_item [4]; row [" Backup_Restore_Memo "] = str_item [5]; row ["CreateDate"] = str_item [6]; dt. rows. add (row) ;}} dt. defaultView. sort = "CreateDate DESC"; // DataTable Sort DataTable dtTemp = dt. defaultView. toTable (); return dtTemp ;} /// <summary> /// obtain the names of all tables in the database /// </summary> /// <returns> </returns> public DataTable GetSysobjects () {StringBuilder StrSql = new StringBuilder (); strSql. Append ("select Name as TABLE_NAME from sysobjects where xtype = 'U' and status> = 0 and Name! = 'Sysdiagrams '"); return DataFactory. sqlDataBase (). getDataTableBySQL (strSql );} /// <summary> /// obtain all the fields of a table // </summary> /// <param name = "object_id"> table name </param> /// <returns> </returns> public DataTable GetSyscolumns (string object_id) {DataTable dt = new DataTable (); StringBuilder strSql = new StringBuilder (); if (! String. IsNullOrEmpty (object_id) & object_id! = "Not selected") {strSql. append (@ "SELECT [column name] =. name, [data type] = B. name, [length] = COLUMNPROPERTY (. id,. name, 'precision '), [empty or not] = case when. isnullable = 1 then' √ 'else' end, [default value] = isnull (e. text, ''), [description] = isnull (g. [value], 'Unspecified description') FROM syscolumns a left join policypes B on. xusertype = B. xusertype inner join sysobjects d on. id = d. id and d. xtype = 'U' and d. name <> 'dtproperties' left join syscomments e on. cdefault = e. id left join sys. extended_properties g on. id = g. major_id and. colid = g. minor_id left join sys. extended_properties f on d. id = f. major_id and f. minor_id = 0 "); strSql. append ("where d. name = '"+ object_id +" 'order by. id,. colorder "); return DataFactory. sqlDataBase (). getDataTableBySQL (strSql);} return dt ;}# endregion