C#.NET通用权限管理在DB2数据库上运行的脚本参考 - 通过程序将数据导入到目标数据库中

简介:

参考代码如下:

// --------------------------------------------------------------------
//  All Rights Reserved , Copyright (C) 2011 , Hairihan TECH, Ltd. 
// --------------------------------------------------------------------

using  System.Data;

namespace  DotNet.Example
{
using  DotNet.BaseManager;
using  DotNet.DbUtilities;

public class  ImportExportData
   {
/// <summary>
///  导出数据库到Oralce
/// </summary>
public void  Export()
       {
this .ExportTable( " Items_Nationality " );
this .ExportTable( " Items_Area " );
this .ExportTable( " Items_AuditStatus " );
this .ExportTable( " Items_Degree " );
this .ExportTable( " Items_Duty " );
this .ExportTable( " Items_Education " );
this .ExportTable( " Items_Express " );
this .ExportTable( " Items_Links " );
this .ExportTable( " Items_MembershipLevels " );
this .ExportTable( " Items_NewsCategory " );
this .ExportTable( " Items_OnSale " );
this .ExportTable( " Items_OrganizeCategory " );
this .ExportTable( " Items_Party " );
this .ExportTable( " Items_Pattern " );
this .ExportTable( " Items_PayCategory " );
this .ExportTable( " Items_PostCategory " );
this .ExportTable( " Items_RoleCategory " );
this .ExportTable( " Items_SalaryItemCategory " );
this .ExportTable( " Items_SendCategory " );
this .ExportTable( " Items_Gender " );
this .ExportTable( " Items_Title " );
this .ExportTable( " Items_Units " );
this .ExportTable( " Items_Wed " );
this .ExportTable( " Items_AuditStatus " );
this .ExportTable( " Items_WorkCategory " );
this .ExportTable( " Items_WorkFlowCategories " );
this .ExportTable( " Items_WorkingProperty " );
this .ExportTable( " Base_Businesscard " );
this .ExportTable( " Base_Comment " );
this .ExportTable( " Base_Contact " );
this .ExportTable( " Base_ContactDetails " );
this .ExportTable( " Base_Exception " );
this .ExportTable( " Base_File " );
this .ExportTable( " Base_Folder " );
this .ExportTable( " Base_Items " );
this .ExportTable( " Base_Log " );
this .ExportTable( " Base_Message " );
this .ExportTable( " Base_News " );

this .ExportTable( " Base_Organize " );
this .ExportTable( " Base_Module " "  SELECT * FROM BASE_MODULE ORDER BY PARENTID, ID  " );
this .ExportTable( " Base_PermissionItem " );
this .ExportTable( " Base_Role " );
this .ExportTable( " Base_Staff " );

this .ExportTable( " Base_Parameter " );
this .ExportTable( " Base_Project " );
this .ExportTable( " Base_Permission " );
this .ExportTable( " Base_PermissionScope " );

this .ExportTable( " Base_Sequence " );

this .ExportTable( " Base_StaffOrganize " );
this .ExportTable( " Base_TableColumns " );
this .ExportTable( " Base_User " );
this .ExportTable( " Base_UserAddress " );
this .ExportTable( " Base_UserOrganize " );
this .ExportTable( " Base_UserRole " );
this .ExportTable( " Base_StaffOrganize " );

/*
           this.ExportTable("Base_WorkFlowActivity");
           this.ExportTable("Base_WorkFlowCurrent");
           this.ExportTable("Base_WorkFlowHistory");
           this.ExportTable("Base_WorkFlowProcess");
*/

           System.Console.ReadLine();
       }

public void  ExportTable( string  tableName)
       {
           ExportTable(tableName.ToUpper(), tableName.ToUpper());
       }

/// <summary>
///  导出一个表
/// </summary>
/// <param name="tableName"> 表名 </param>
/// <param name="table"> 里面的数据 </param>
public void  ExportTable( string  tableName,  string  table)
       {
//  这里是获取目标数据表的方法
           IDbHelper sourceDB  = new  SqlHelper( " Data Source=192.168.0.121;Initial Catalog=UserCenterV36;User Id = sa ; Password = xx; " );
           sourceDB.Open();
           DataTable dataTable 
= new  DataTable(tableName);
if  (tableName.Equals(table))
           {
               dataTable 
=  sourceDB.Fill( " SELECT * FROM  " +  table);
           }
else
           {
               dataTable 
=  sourceDB.Fill(table);
           }
           sourceDB.Close();

//  这里是目标表的数据插入处理
//  IDbHelper targetDB = new OracleHelper("Data Source=KANGFU;user=usercenter;password=xx;");
           IDbHelper targetDB  = new  DB2Helper( " Database=UCV36;UserID=JIRIGALA;Password=xx;Server=JIRIGALA-PC; " );
           targetDB.Open();
           targetDB.BeginTransaction();
           SQLBuilder sqlBuilder 
= new  SQLBuilder(targetDB);
try
           {
//  清除表数据
//  targetDB.ExecuteNonQuery(" TRUNCATE TABLE " + tableName);
               targetDB.ExecuteNonQuery( "  DELETE FROM  " +  tableName);
//  创建配套的序列
//  targetDB.ExecuteNonQuery("create sequence SEQ_" + tableName.ToUpper() + " as bigint start with 1000000 increment by 1 minvalue 10000 maxvalue 99999999999999999 cycle cache 20 order");
//  targetDB.ExecuteNonQuery("create sequence SEQ_" + tableName + " minvalue 1 maxvalue 999999999999999999999999 start with 1 increment by 1 cache 20");
int  r  = 0 ;
for  (r  = 0 ; r  <  dataTable.Rows.Count; r ++ )
               {
                   sqlBuilder.BeginInsert(tableName);
for  ( int  i  = 0 ; i  <  dataTable.Columns.Count; i ++ )
                   {
                       sqlBuilder.SetValue(dataTable.Columns[i].ColumnName, dataTable.Rows[r][dataTable.Columns[i].ColumnName]);
                   }
                   sqlBuilder.EndInsert();
//  System.Console.WriteLine("表 " + tableName + " 已插入第 " + r.ToString() + " 行");
               }
               System.Console.WriteLine(
"  - - 表  " +  tableName  + "  共插入  " +  r.ToString()  + "  行 " );
               targetDB.CommitTransaction();
           }
catch  (System.Exception exception)
           {
//  targetDB.RollbackTransaction();
               System.Console.WriteLine(tableName  + "  --  " +  exception.Message);
           }
finally
           {
               targetDB.Close();
           }
       }
   }
}





本文转自 jirigala 51CTO博客,原文链接:http://blog.51cto.com/2347979/1197383,如需转载请自行联系原作者

相关文章
|
3月前
|
关系型数据库 MySQL 数据库连接
python脚本:连接数据库,检查直播流是否可用
【10月更文挑战第13天】本脚本使用 `mysql-connector-python` 连接MySQL数据库,检查 `live_streams` 表中每个直播流URL的可用性。通过 `requests` 库发送HTTP请求,输出每个URL的检查结果。需安装 `mysql-connector-python` 和 `requests` 库,并配置数据库连接参数。
146 68
|
2月前
|
算法 Java 测试技术
Benchmark.NET:让 C# 测试程序性能变得既酷又简单
Benchmark.NET是一款专为 .NET 平台设计的性能基准测试框架,它可以帮助你测量代码的执行时间、内存使用情况等性能指标。它就像是你代码的 "健身教练",帮助你找到瓶颈,优化性能,让你的应用跑得更快、更稳!希望这个小教程能让你在追求高性能的路上越走越远,享受编程带来的无限乐趣!
148 13
|
4月前
|
SQL 关系型数据库 MySQL
|
5月前
|
SQL 关系型数据库 MySQL
MySQL数据库中给表添加字段并设置备注的脚本编写
通过上述步骤,你可以在MySQL数据库中给表成功添加新字段并为其设置备注。这样的操作对于保持数据库结构的清晰和最新非常重要,同时也帮助团队成员理解数据模型的变化和字段的具体含义。在实际操作中,记得调整脚本以适应具体的数据库和表名称,以及字段的详细规范。
131 8
|
4月前
|
XML 存储 安全
C#开发的程序如何良好的防止反编译被破解?ConfuserEx .NET混淆工具使用介绍
C#开发的程序如何良好的防止反编译被破解?ConfuserEx .NET混淆工具使用介绍
204 0
|
19天前
|
关系型数据库 MySQL 数据库连接
数据库连接工具连接mysql提示:“Host ‘172.23.0.1‘ is not allowed to connect to this MySQL server“
docker-compose部署mysql8服务后,连接时提示不允许连接问题解决
|
6天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
73 42
|
24天前
|
缓存 关系型数据库 MySQL
【深入了解MySQL】优化查询性能与数据库设计的深度总结
本文详细介绍了MySQL查询优化和数据库设计技巧,涵盖基础优化、高级技巧及性能监控。
173 0
|
2月前
|
存储 Oracle 关系型数据库
数据库传奇:MySQL创世之父的两千金My、Maria
《数据库传奇:MySQL创世之父的两千金My、Maria》介绍了MySQL的发展历程及其分支MariaDB。MySQL由Michael Widenius等人于1994年创建,现归Oracle所有,广泛应用于阿里巴巴、腾讯等企业。2009年,Widenius因担心Oracle收购影响MySQL的开源性,创建了MariaDB,提供额外功能和改进。维基百科、Google等已逐步替换为MariaDB,以确保更好的性能和社区支持。掌握MariaDB作为备用方案,对未来发展至关重要。
71 3
|
2月前
|
安全 关系型数据库 MySQL
MySQL崩溃保险箱:探秘Redo/Undo日志确保数据库安全无忧!
《MySQL崩溃保险箱:探秘Redo/Undo日志确保数据库安全无忧!》介绍了MySQL中的三种关键日志:二进制日志(Binary Log)、重做日志(Redo Log)和撤销日志(Undo Log)。这些日志确保了数据库的ACID特性,即原子性、一致性、隔离性和持久性。Redo Log记录数据页的物理修改,保证事务持久性;Undo Log记录事务的逆操作,支持回滚和多版本并发控制(MVCC)。文章还详细对比了InnoDB和MyISAM存储引擎在事务支持、锁定机制、并发性等方面的差异,强调了InnoDB在高并发和事务处理中的优势。通过这些机制,MySQL能够在事务执行、崩溃和恢复过程中保持
109 3

热门文章

最新文章