C#来做oracle还原,调用oracle自带函数imp.exe时,需要注意的是:
1、imp.exe 中fromuser 和touser两个关键字; fromuser与exp.exe中的owner对应,为表的所有者,都可以是多个参数,如:fromuser=(A,B,C)
2、imp.exe 进行恢复数据库时,要确定一下恢复用户(方案)的表空间,一般默认为users空间
3、在获取到表空间权限后,要对用户进行恢复权限设置,主要是对表空间的限制,一般处理:grant unlimited tablespace to user(自己的用户)
4、程序中设置了oracle服务端的exp和imp的路径
注意:在C#做备份和还原的时候,都是调用的oracle服务器的自带函数
   在用进程来调用备份和还原时,备份完成和结束后,要进行进程释放。 //开始恢复数据库
private void button1_Click(object sender, EventArgs e)
{ string tables = ""; //创建要还原的方案
//从备份的方案中读取
FileStream fs=new FileStream (textBox6.Text,FileMode.Open);
StreamReader smread=new StreamReader(fs);
smread.BaseStream.Seek(,SeekOrigin.Begin);
string strLine = "";
string backusers = "";
while ((strLine=smread.ReadLine()) != null)
{
backusers += strLine + ",";
} if (backusers.Length > )
{
backusers = backusers.Substring(, backusers.Length - );
tables = backusers;
}
String[]userArr=backusers.Split(',');
string sqluser="";
String[] marks;
string newtables = "";
using (OracleConnection oracon = orclConnection())
{
try
{
oracon.Open();
}
catch (Exception ex)
{
MessageBox.Show("链接数据库错误,错误原因:"+ex.Message.ToString());
}
using (OracleTransaction tran = oracon.BeginTransaction())
{
using (OracleCommand com = new OracleCommand())
{
com.Transaction = tran; string newuser = "";
com.Connection = oracon;
//com.Connection.Open(); foreach (string s in userArr)
{
newuser = s; //判断是否按照默认的标识进行还原
if (!checkBox1.Checked)//不默认
{
newuser = "";
//tables = "";
//修改还原的方案名称后缀(标识)
marks = s.Split('_');
//修改标识
marks[marks.Count() - ] = textBox2.Text.ToUpper();
foreach (string mark in marks)
{
newuser += mark + "_";
}
newuser = newuser.Substring(, newuser.Length - );
newtables += newuser + ",";
} com.CommandText = "Select count(*) from all_users where username='" + newuser + "'";
int i = Convert.ToInt32(com.ExecuteScalar()); //如果存在,删除后还原
if (i > )
{
sqluser = "drop user "+newuser+" cascade"; com.CommandText = sqluser;
try
{
com.ExecuteNonQuery();
com.CommandText = "create user " + newuser + " identified by " + newuser + " default tablespace users";
com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
tran.Rollback();
}
} if (i == )
{
sqluser = "create user " + newuser + " identified by " + newuser+" default tablespace users";
com.CommandText = sqluser;
try
{
com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
tran.Rollback();
}
} sqluser = "grant connect,resource,dba to " + newuser;
com.CommandText = sqluser;
com.ExecuteNonQuery(); sqluser = "alter user system quota unlimited on users" ;
com.CommandText = sqluser;
com.ExecuteNonQuery(); //指定还原的方案为还原默认的表空间
sqluser = "grant unlimited tablespace to "+newuser ;
com.CommandText = sqluser;
com.ExecuteNonQuery();
} if (!checkBox1.Checked)
{
tables = newtables.Substring(, newtables.Length - );
}
tran.Commit();
}
}
} //} string filename = textBox5.Text;//恢复文件路径
//导入程序路径
Process p = new Process();
//p.StartInfo.FileName= "D:\\app\\oracle\\product\\11.2.0\\dbhome_1\\BIN\\imp.exe";
p.StartInfo.FileName = System.Configuration.ConfigurationSettings.AppSettings["pathrestroe"].ToString();
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments = "system/system@orcl file=" + filename + " fromuser=("+backusers+") touser=(" +tables+ ") ignore=y" ;
//p.StartInfo.Arguments = "system/system@orcl file=" + filename + " fromuser=HYGISTK_CONTROLLINE_ZL2 touser=HYGISTK_CONTROLLINE_ZL ignore=y";
p.Start();
p.WaitForExit();
p.Dispose();
}

C#oracle还原imp实例的更多相关文章

  1. 深入理解Oracle的imp/exp 和各版本之间的规则

    Oracle数据中IMP/EXP工具可用于对数据进行迁移.IMP命令用于把Dmp文件从本地导入到远程数据库服务器,而EXP命令则是把数据从远程数据库服务器导出到本地的Dmp文件.其功能相当于Oracl ...

  2. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念

    版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念 系统环境: 操作系统:RH EL5-64 Oracle 软件: Ora ...

  3. Linux平台oracle 11g单实例 + ASM存储 安装部署 快速参考

    操作环境:Citrix虚拟化环境中申请一个Linux6.4主机(模板)目标:创建单机11g + ASM存储 数据库 1. 主机准备 2. 创建ORACLE 用户和组成员 3. 创建以下目录并赋予对应权 ...

  4. oracle中imp命令详解 .

    转自http://www.cnblogs.com/songdavid/articles/2435439.html oracle中imp命令详解 Oracle的导入实用程序(Import utility ...

  5. 【转】Oracle - 数据库的实例、表空间、用户、表之间关系

    [转]Oracle - 数据库的实例.表空间.用户.表之间关系 完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机 ...

  6. oracle中imp命令具体解释

    oracle中imp命令具体解释 Oracle的导入有用程序(Import utility)同意从数据库提取数据,而且将数据写入操作系统文件.imp使用的基本格式:imp[username[/pass ...

  7. oracle exp imp

    oracle exp/imp

  8. oracle在imp订单具体解释

    oracle在imp订单具体解释 Oracle导入实用程序(Import utility)同意从数据库中提取数据,和写入数据到一个操作系统文件项目.imp所用的基本格式:imp[username[/p ...

  9. oracle数据库与实例

    ========================================================================================== oracle数据库 ...

随机推荐

  1. PHP留言小练习

    实现功能: 留言.搜索.编辑.删除.详情页.时间.点击量 页面划分: index.html(留言列表页) add.html(留言页) edit.php(编辑页) del.php(删除页) view.p ...

  2. 「LOJ#10072」「一本通 3.2 例 1」Sightseeing Trip(无向图最小环问题)(Floyd

    题目描述 原题来自:CEOI 1999 给定一张无向图,求图中一个至少包含 333 个点的环,环上的节点不重复,并且环上的边的长度之和最小.该问题称为无向图的最小环问题.在本题中,你需要输出最小环的方 ...

  3. 【Lintcode】098.Sort List

    题目: Sort a linked list in O(n log n) time using constant space complexity. Example Given 1->3-> ...

  4. Html 5 简介

    html5 是下一代的html 什么是 html5? html5 将成为 html.xhtml 以及 html dom 的新标准. html 的上一个版本诞生于 1999 年.自从那以后,web 世界 ...

  5. 为BindingList添加Sort

    最近在优化WPF性能时, 发现在特定条件下BindingList比ObservableCollection性能更高, 因为它提供Disable/Enable 更改通知的方法.这样我们可以不需要很频繁的 ...

  6. ACM-ICPC2018焦作网络赛 Mathematical Curse(dp)

    Mathematical Curse 22.25% 1000ms 65536K   A prince of the Science Continent was imprisoned in a cast ...

  7. 如何获取AppStore上应用的ipa安装包

    1.首先你得去下载一个Apple Configurator 2,我们通过这个工具来获取ipa包,从AppStore上下载安装你需要获取的App 2.连接手机,打开Apple Configurator ...

  8. python + requests实现的接口自动化框架详细教程

    前段时间由于公司测试方向的转型,由原来的web页面功能测试转变成接口测试,之前大多都是手工进行,利用postman和jmeter进行的接口测试,后来,组内有人讲原先web自动化的测试框架移驾成接口的自 ...

  9. 938. Range Sum of BST

    Given the root node of a binary search tree, return the sum of values of all nodes with value betwee ...

  10. <!--[if !IE]> 的用法

    除IE外都可识别